Linux配置固定静态IP地址
基本配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | vi /etc/sysconfig/network-scripts/ifcfg-eth0 vi /etc/udev/rules.d/70-persistent-net.rules NAME="System eth0" DEVICE=eth0 IPADDR=192.168.59.130 NETMASK=255.255.255.0 NETWORK=192.168.59.0 BROADCAST=192.168.59.255 GATEWAY=192.168.59.2 ONBOOT=yes USERCTL=no BOOTPROTO=static #HWADDR=00:0c:29:97:f1:5b TYPE=Ethernet IPV6INIT=no DNS1=202.96.209.5 DNS2=8.8.8.8 ifconfig eth1 192.168.210.108 broadcast 192.168.210.254 netmask 255.255.255.0 ifconfig eth1 192.168.59.130 broadcast 192.168.59.1 netmask 255.255.255.0 ifconfig eth0 192.168.59.130 netmask 255.255.255.0 gw 192.168.129.1 systemctl stop NetworkManager systemctl mask NetworkManager systemctl disable NetworkManager chkconfig NetworkManager off chkconfig network on service NetworkManager stop service network start -- red hat重启网卡 service network restart /etc/rc.d/init.d/network restart -- suse重启网卡 service network restart rcnetwork restart /etc/rc.d/init.d/network restart -- 卸载网卡 ifconfig eth0 down -- 单独重启网卡 ifdown eth0 && ifup eth0 ifconfig eth0 down && ifconfig eth0 up |
动态IP地址
1 2 3 4 5 6 7 8 9 10 | DEVICE=eth0 ONBOOT=yes USERCTL=no BOOTPROTO=dhcp HWADDR=00:0c:29:97:f1:5b TYPE=Ethernet PEERDNS=yes IPV6INIT=no |
图形界面配置
1 2 3 4 | [root@rhel6 ~]# export LANG=C [root@rhel6 ~]# setup [root@rhel6 ~]# |
单个网卡添加多个IP
可以作为VIP进行漂移。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | -- 单个网卡添加多个IP(注意子网掩码需要和宿主网卡一样) ifconfig eth0:1 192.168.59.136/24 ifconfig eth0:1 192.168.59.131 netmask 255.255.255.0 up ifconfig eth0:1 192.168.59.132 netmask 255.255.255.0 up ifconfig eth0:1 172.72.6.56/16 netmask 255.255.0.0 up ifup eth0:0 ip addr add 172.72.6.56/16 dev eth0 label eth0:1 -- 编辑: /etc/sysconfig/network-scripts/ifcfg-eth0:1 修改DEVICE=eth0:1和IPADDR=192.168.59.131 -- 删除的话: ip addr del 192.168.59.135/24 dev eth0 ip addr del 172.72.6.56/16 dev eth0 |