CentOS下双网卡设置方法

来源:互联网 发布:电视台直播软件 编辑:程序博客网 时间:2024/04/30 08:27

CentOS 双网卡双 IP 设置, 网络上找的基本比较含糊.

最近在弄 openstackEssex, 用到了双网卡双 IP, 在此做个备忘.

系统环境: CentOS6.3

网络环境: 两个 IP 地址(双网卡),192.168.30.155 和 111.111.10.6, 掩码是 255.255.255.0

这两个子网的网关地址分别是:192.168.30.1 和 111.111.10.1

1. 为网卡 eth0 配置 ip 地址192.168.30.155, 为网卡 eth2 配置 ip 地址为111.111.10.6配置文件为:

  /etc/sysconfig/network-scripts/ifcfg-em1

  /etc/sysconfig/network-scripts/ifcfg-em2

2. 配置默认网关为任意一个. 这个默认网关, 决定了系统主动去使用网络时, 使用的接口.

   修改配置文件: /etc/sysconfig/network, 添加内容:

  GATEWAYDEV=eth0

3. 编辑路由表

   修改/etc/iproute2/rt_tables, 添加内容:

   252 net2

   251 net3

   修改/etc/rc.local 添加原路返回路由

   iproute flush table net2

   ip route add defaultvia 192.168.30.1 dev eth0 src 192.168.30.155 table net2

   iprule add from 192.168.30.155 table net2

 

   iproute flush table net3

   ip route add defaultvia 111.111.10.1 dev eth2 src 111.111.10.6 table net3

   iprule add from 111.111.10.6 table net3

 

 

4. 最后记得重启机器

 

0 0