CentOS 双网卡双 IP 设置

来源:互联网 发布:陈赫淘宝店叫什么 编辑:程序博客网 时间:2024/04/30 10:14
系统环境: CentOS6.3
网络环境: 两个 IP 地址(双网卡), 192.168.18.160 和 192.168.19.160, 掩码是 255.255.255.0
这两个子网的网关地址分别是: 192.168.18.254 和 192.168.19.254
 
1. 为网卡 em2 配置 ip 地址 192.168.19.160, 为网卡 em3 配置 ip 地址为 192.168.18.160 配置文件为:
   /etc/sysconfig/network-scripts/ifcfg-em2
   /etc/sysconfig/network-scripts/ifcfg-em3

2. 配置默认网关为任意一个. 这个默认网关, 决定了系统主动去使用网络时, 使用的接口.
   修改配置文件: /etc/sysconfig/network, 添加内容:
   GATEWAYDEV=em3

3. 编辑路由表
   修改 /etc/iproute2/rt_tables, 添加内容:
   252  net2
   251  net3

   修改 /etc/rc.local 添加原路返回路由
   ip route flush table net2
   ip route add default via 192.168.18.254 dev em3 src 192.168.18.160 table net2
   ip rule add from 192.168.18.160 table net2

   ip route flush table net3
   ip route add default via 192.168.19.254 dev em2 src 192.168.19.160 table net3
   ip rule add from 192.168.19.160 table net3

4. 在 Windows 下验证, 跟踪路由情况:
   ping 192.168.18.160
   ping 192.168.19.160

   tracert 192.168.18.160
   tracert 192.168.19.160

5. 桥接模式下注意事项(通过 kvm 虚拟机实践)
a. 默认网关一定要设置在桥上, 如(br100):
   IPADDR=192.168.19.160
   NETMASK=255.255.255.0
   GATEWAY=192.168.19.254
   修改配置文件: /etc/sysconfig/network 的 GATEWAYDEV 为桥:
   GATEWAYDEV=br100
b. 桥上不能设置 UUID、HWADDR, 一定要设置在物理网卡上, 否则重启后找不到网卡.
   PS: 在此次跌倒无数次, 每次都 rm -rf /etc/udev/rules.d/70-persistent-net.rules,  修改 em2 并关闭桥接.
   重启后 em2 正常, 每次又开启桥并 service network restart, 桥正常了. 这样来来回回折腾死了. 
   最后才发现该问题, 必须设置在物理网卡上.  缺乏网络知识啊!
c. 原路返回 /etc/rc.local 处对应的地方需要修改成桥的名称, 如:
   ip route flush table net3
   ip route add default via 192.168.19.254 devbr100 src 192.168.19.160 table net3

   ip rule add from 192.168.19.160 table net3

6. 最后记得重启机器
原创粉丝点击