linux 系统单网卡绑定多个IP地址方法
如果linux 系统只有一个物理网卡,而在实际使用中,有时需要配置单网卡具备多个IP 地址。
步骤:
1、root登录 linux系统
2、查看现有网络配置
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.50.222
NETMASK=255.255.255.0
GATEWAY=192.168.50.1
3、配置新的虚拟网卡
注:仍然保留原有ifcfg-eth0文件,所以采用复制方式。
[root@localhost network-scripts]# cp ifcfg-eth0ifcfg-eth0:1
[root@localhost network-scripts]# viifcfg-eth0:1
DEVICE=eth0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.1.1.100
NETMASK=255.255.255.0
GATEWAY=10.1.1.1
[root@localhost network-scripts]# service network restart
4、查看目前路由
route -n
DestinationGatewayGenmaskFlags MetricRefUseIface
192.168.50.00.0.0.0255.255.255.0 U000 eth0
10.1.1.00.0.0.0255.255.255.0 U000 eth0
0.0.0.0192.168.50.1 0.0.0.0UG000 eth0
如果只需要默认路由,则这样设置就可以啦。
如果需要不同的源IP地址走不同的默认路由,则定制举例如下:
route add -net 192.168.50.0/24 gw 192.168.50.1 dev eth0
route add -net 10.1.1.0/24 gw 10.1.1.1 deveth0:1
这样,源地址192.168.50.x网段默认走 eth0;源地址10.1.1.x的网段默认走eth0:1
其它的IP默认走eth0
查看路由信息如下:
route -n
DestinationGatewayGenmaskFlags MetricRefUseIface
192.168.50.00.0.0.0255.255.255.0 U000 eth0
192.168.50.0192.168.50.1255.255.255.0 UG000 eth0
10.1.1.010.1.1.1255.255.255.0 UG000 eth0
10.1.1.00.0.0.0255.255.255.0 U000 eth0
169.254.0.00.0.0.0255.255.0.0U000 eth0
0.0.0.0192.168.50.10.0.0.0UG000 eth0
用route -n 命令增加的路由在网络重启后,则路由丢失,可通过增加到rc.local 等多种方式实现永久保持。
<完>
原文:http://blog.sina.com.cn/s/blog\_54dd9b610100h7ww.html
还没有评论,来说两句吧...