網絡屬性配置第三種方式——修改配置文件

網絡屬性配置第三種方式——修改配置文件
IP ,MASK,GW,DNS相關的配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0
路由相關的配置文件:/etc/sysconfig/network-scripts/route-enth0(這個文件默認不存在,需要手動去創建)
(1)/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost network-scripts]# cat ifcfg-eth0
DEVICE=eth0 (此配置文件應用到的設備)
HWADDR=00:0C:29:2D:9F:69(或MACADDR)
TYPE=Ethernet (接口類型)
UUID=8d1fa98d-630a-4415-8772-a9ad2fe1833d (設備的唯一標識)
ONBOOT=yes (系統引導時激活設備)
NM_CONTROLLED=yes (network manager此網卡是否接受nm控制,建議centos6上禁用)
BOOTPROTO=static (協議dhcp,none)
IPADDR=192.168.176.130
NETMASK=255.255.255.0
GATEWAY=192.168.176.1 (默認網關)
NAME=eth0
DNS1=1.1.1.1
DNS2=8.8.8.8
DNS=114.114.114.114
USERCTL=no(普通用戶是否可控制此設備)
PEERNDS=(如果BOOTPROTO的值為dhcp,是否允許dhcp分配的server分配的dns服務器指向信息直接覆蓋至/etc/resolv.conf文件中)
(2)路由/etc/sysconfig/network-scripts/route-enth0
兩種風格:
!!指明TARGET VIA (經由) GW
!!每三行定義一條路由
ADDRESS1=TARGET
NETMASK1=mask
GATEWAY1=GW
eg:每行一個
[root@localhost network-scripts]# vi route-eth0
172.20.0.0/16 via 192.168.176.1
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.176.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.20.0.0 192.168.176.1 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.176.1 0.0.0.0 UG 0 0 0 eth0
eg:每三行一個
[root@localhost network-scripts]#vim route-eth0
ADDRESS0=172.20.0.0
NETMASK0=255.255.0.0
GATEWAY0=192.168.176.1
ADDRESS1=172.30.0.0
NETMASK1=255.255.0.0
GATEWAY1=192.168.176.1
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.176.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.30.0.0 192.168.176.1 255.255.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.20.0.0 192.168.176.1 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.176.1 0.0.0.0 UG 0 0 0 eth0
給網卡配置多地址:
第一個種:ifconfig
ifconfig eth0:0
第二種:ip
ip addr add
第三種:配置文件
ifcfg-eth0:0(指明網卡別名)
DEVICE=eth0:0
[root@localhost network-scripts]# ifconfig eth0:0 192.168.0.22/24 up
[root@localhost network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:2D:9F:69
inet addr:192.168.176.130 Bcast:192.168.176.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe2d:9f69/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3018 errors:0 dropped:0 overruns:0 frame:0
TX packets:2728 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:308183 (300.9 KiB) TX bytes:312869 (305.5 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:2D:9F:69
inet addr:192.168.0.22 Bcast:192.168.0.255 Mask
注意:網卡別名不能使用dhcp協議引導
網絡接口識別并命名相關的udev配置文件
/etc/udev/rules.d/70-persistent-net.rules
卸載網卡驅動:
#modprobe -r e1000

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/97666

发表评论

登录后才能评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1823388528@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班