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

Destination    Gateway        Genmask        Flags MetricRef    UseIface
192.168.50.0   0.0.0.0        255.255.255.0               0 eth0
10.1.1.0      0.0.0.0        255.255.255.0               0 eth0
0.0.0.0        192.168.50.1   0.0.0.0        UG             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               0 eth0
192.168.50.0   192.168.50.1   255.255.255.0  UG             0 eth0
10.1.1.0       10.1.1.1       255.255.255.0  UG             0 eth0
10.1.1.0       0.0.0.0        255.255.255.0               0 eth0
169.254.0.0    0.0.0.0        255.255.0.0                 0 eth0
0.0.0.0        192.168.50.1   0.0.0.0        UG             0 eth0

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

<完>

原文:http://blog.sina.com.cn/s/blog_54dd9b610100h7ww.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值