1.vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="none"
HWADDR="BC:AE:C5:11:4C:D9"
NM_CONTROLLED="yes"
ONBOOT="yes"
IPADDR=192.168.2.199
PREFIX=24
GATEWAY=192.168.2.1
TYPE="Ethernet"
UUID="cb660fe2-f744-4395-a220-87fcd00d57ec"
.設(shè)置靜態(tài)IP地址.
(1).命令行設(shè)置(該方式只是臨時(shí)設(shè)置,系統(tǒng)重啟后失效)
[1].設(shè)置IP和掩碼
ifconfig 接口名(如eth0) IP地址 netmask 子網(wǎng)掩碼
[2].設(shè)置網(wǎng)關(guān)
route add default gw 默認(rèn)網(wǎng)關(guān)
[3].設(shè)置DNS服務(wù)器地址
echo "nameserver DNS服務(wù)器地址">/etc/resolv.conf
實(shí)例:假設(shè)設(shè)置eth0的IP:192.168.1.100,DNS:192.168.1.12
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
route add default gw 192.168.1.1
echo "nameserver=192.168.1.12">/etc/resolv.conf
(2).修改文件來實(shí)現(xiàn)配置網(wǎng)絡(luò)(需要重啟網(wǎng)絡(luò)接口)
[1].修改IP地址,文件:/etc/sysconfig/network-scripts/ifcfg-接口名
這里假設(shè)網(wǎng)絡(luò)接口名為eth0.
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 (注:這里填的是網(wǎng)絡(luò)接口名)
BOOTPROTO=none
ONBOOT=yes (注:是否隨系統(tǒng)啟動(dòng))
IPADDR=192.168.1.100(注:這里填寫的是IP地址)
PREFIX=24 (注:這里填寫的是掩碼的長度)
GATEWAY=192.168.1.1( 注:這里寫的是網(wǎng)關(guān))
EOF
[2].修改DNS
echo "nameserver DNS服務(wù)器地址">/etc/resolv.conf
[3].重啟網(wǎng)絡(luò)接口(假設(shè)為eth0)
ifup eth0(注:這里寫的是接口名)