Centos服务器新增多IP配置详解

操作步骤

#进入网卡配置文件目录下
[root@localhost ]# cd /etc/sysconfig/network-scripts 

#备份网卡配置文件
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth0.bak 

#查看网卡配置文件
[root@localhost network-scripts]# cat ifcfg-eth0
=============
DEVICE="eth0"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.10
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
DNS1=8.8.8.8
ARPCHECK=no
NM_CONTROLLED=no
=============

#进入网卡配置文件,添加新IP配置内容如下:
[root@localhost network-scripts]# vim ifcfg-eth0
============= 
DEVICE="eth0"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.10
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
DNS1=8.8.8.8
ARPCHECK=no
NM_CONTROLLED=no
#标红为添加新增IP配置信息
IPADDR1=192.168.0.11
NETMASK1=255.255.255.0

=============

IPADDR1=这个1是指新IP地址的序号
NETMASK1=这个1是指新IP掩码的序号
如果需要增加三个IP则内容如下:
IPADDR1=192.168.0.11
NETMASK1=255.255.255.0
IPADDR2=192.168.0.12
NETMASK2=255.255.255.0
IPADDR3=192.168.0.13

NETMASK3=255.255.255.0

如果要添加不同网段的IP,IP配置规则同样如此,不需要增加新网关

#重启网卡配置文件
 [root@localhost network-scripts]# /etc/init.d/network  restart

#查看新增加的IP
[root@localhost network-scripts]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether e0:97:96:0c:ce:13 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.10/24 brd 255.255.255.0 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.0.11/24 brd 255.255.255.0 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::e297:96ff:fe0c:ce13/64 scope link
valid_lft forever preferred_lft forever

#使用另外一台主机ping新增加的IP地址
[root@localhost]# ping  192.168.0.11
PING 192.168.0.11 (192.168.0.11) 56(84) bytes of data.
64 bytes from 192.168.0.11: icmp_seq=1 ttl=64 time=0.042 ms
64 bytes from 192.168.0.11: icmp_seq=2 ttl=64 time=0.031 ms
64 bytes from 192.168.0.11: icmp_seq=3 ttl=64 time=0.031 ms
64 bytes from 192.168.0.11: icmp_seq=4 ttl=64 time=0.030 ms

  • 0 个用户发现这个很有用
这个答案有用吗?