您的位置:首页 > 运维架构 > Linux

linux 系统单网卡绑定多个IP地址方法

2014-10-19 15:35 661 查看
如果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

Destination Gateway Genmask Flags MetricRef UseIface

192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

0.0.0.0 192.168.50.1 0.0.0.0 UG 0 0 0 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

Destination Gateway Genmask Flags MetricRef UseIface

192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

192.168.50.0 192.168.50.1 255.255.255.0 UG 0 0 0 eth0

10.1.1.0 10.1.1.1 255.255.255.0 UG 0 0 0 eth0

10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

0.0.0.0 192.168.50.1 0.0.0.0 UG 0 0 0 eth0

用route -n 命令增加的路由在网络重启后,则路由丢失,可通过增加到rc.local 等多种方式实现永久保持。

<完>

原文:http://blog.sina.com.cn/s/blog_54dd9b610100h7ww.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: