单块网卡绑定多个ip,网上介绍的太多了。方法如下
1、复制虚拟网卡配置文件
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
2、编辑eth0:0
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
# Broadcom Corporation NetXtreme
DEVICE=eth0:0 #虚拟网卡的设备名
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.0.0.3 #绑定的ip地址
NETMASK=255.0.0.0
GATEWAY=10.0.0.1
HWADDR=00:0C:29:80:B6:7F #有文档提示此处mac不能更改
然后保存ifcfg-eth1:0文件
3、重启网络服务
[root@xxxx network-scripts]# service network restart
要添加多个ip方法如上,只需复制eth0:x。。。。。。
网卡聚合绑定多个ip方法
首先介绍网卡聚合
【服务器双网卡绑定(网卡聚合)】
1.新建/etc/sysconfig/network-scripts/ifcfg-bond0文件
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.0.0.4
NETMASK=255.0.0.0
GATEWAY=10.0.0.1
USERCTL=no
2.更改/etc/sysconfig/network-scripts/ifcfg-eth0网卡属性
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
USERCTL=no
3.更改/etc/sysconfig/network-scripts/ifcfg-eth1网卡的属性
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
USERCTL=no
4.编辑/etc/modprobe.conf文件,加入以下内容
alias bond0 bonding
options bond0 miimon=100 mode=1 #数字1为网卡冗余,0则为负载均衡。此处千万注意。
5.加入/etc/rc.d/rc.local启动项
ifenslave bond0 eth0 eth1
6.启动网卡
ifconfig bond0 10.0.0.4 up
ifenslave bond0 eth0 eth1
如需绑定多个ip请按如下操作
cp /etc/sysconfig/network-scripts/ifcfg-bond0 /etc/sysconfig/network-scripts/ifcfg-bond0:0
vi /etc/sysconfig/network-scripts/ifcfg-bond0:0
DEVICE=bond0:0 #网卡名称
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.0.0.5 #新ip
NETMASK=255.0.0.0
GATEWAY=10.0.0.1
USERCTL=no
保存并启动网卡
ifup ifcfg-bond0:0
另外在做这个实验时,我没有把单块网卡绑定的文件删除(ifcfg-eth0:0)
后来发现这个ip(10.0.0.3)依然可以访问。
在输入ifconfig后显示
bond0 Link encap:Ethernet HWaddr 00:0C:29:80:B6:7F
inet addr:10.0.0.4 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::20c:29ff:fe80:b67f/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:1065 errors:0 dropped:0 overruns:0 frame:0
TX packets:1344 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:86199 (84.1 KiB) TX bytes:151029 (147.4 KiB)
bond0:0 Link encap:Ethernet HWaddr 00:0C:29:80:B6:7F
inet addr:10.0.0.5 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
eth0 Link encap:Ethernet HWaddr 00:0C:29:80:B6:7F
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:897 errors:0 dropped:0 overruns:0 frame:0
TX packets:1335 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:68316 (66.7 KiB) TX bytes:150719 (147.1 KiB)
Interrupt:67 Base address:0x2000
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:80:B6:7F
inet addr:10.0.0.3 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
Interrupt:67 Base address:0x2000
eth1 Link encap:Ethernet HWaddr 00:0C:29:80:B6:7F
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:169 errors:0 dropped:0 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:17943 (17.5 KiB) TX bytes:1018 (1018.0 b)
Interrupt:75 Base address:0x2080
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 b) TX bytes:560 (560.0 b)
转载于:https://blog.51cto.com/yjw1983/413170