Centos /Debian绑定多个ip的教程

VPS技术分享

Centos /Debian绑定多个ip的教程

2021-11-01 22:04


                                            




一、Centos 6单网卡添加多个IP
1、查看网卡信息

ip addr

IPv4绑定的是哪个网卡,之后的操作就需要把其他IP绑定到这个网卡上,比如网卡是eth1

2、添加IP

登录ssh使用root命令执行:

cd /etc/sysconfig/network-scripts/
cp ifcfg-eth1 ifcfg-eth1:1
cp ifcfg-eth1 ifcfg-eth1:2
cp ifcfg-eth1 ifcfg-eth1:3
cp ifcfg-eth1 ifcfg-eth1:4

以此类推,有多少就添加多少。

3、vi编辑,或者使用WinSCP工具修改

vi ifcfg-eth1:1

i开始编辑文本内容,找到DEVICE=eth1这一行,将其改为DEVICE=eth1:1,找到IPADDR=xxx.xxx.xxx.xxx这一行,替换成新的IP即可!然后按ESC建,然后输入:wq保存退出vi编辑。

4、重启生效

chkconfig NetworkManager off
chkconfig network on
service NetworkManager stop
service network start

或者

systemctl restart network.service

二、Centos 7单网卡添加多个IP
1、查看网卡信息

ip addr

IPv4绑定的是哪个网卡,之后的操作就需要把其他IP绑定到这个网卡上,比如网卡是eth1

2、添加IP

登录ssh使用root命令执行:

cd /etc/sysconfig/network-scripts/
vi ifcfg-eno1

找到

IPADDR="172.245.xxx.xxx"
PREFIX="28"

然后下一行添加:

IPADDR1="172.245.xxx.xxx"
PREFIX1="28"
IPADDR2="172.245.xxx.xxx"
PREFIX2="28"

其中28是根据是主机商提供的IP段填写。

3、重启

chkconfig NetworkManager off
chkconfig network on
service NetworkManager stop
service network start

或者

systemctl restart network.service

三、Debian单网卡添加多个IP

1、编辑/etc/network/interfaces文件,按如下格式添加:

auto eth0
iface eth0 inet static
address 8.8.8.115
netmask 255.255.255.0
network 172.16.3.0
broadcast 172.16.3.255
gateway 172.16.3.1

auto eth0:1
iface eth0:1 inet static
address 8.8.8.116
netmask 255.255.0.0
network 10.16.0.0
broadcast 10.16.255.255

2、创建/etc/network/ifstate,添加:

lo=lo
eth0=eth0
eth0:1=eth0:1

3、最后,重启网络。

/etc/init.d/networking restart