公司IDC机房服务器上部署了一套外网LB环境,默认配置的是外网ip的路由地址,由于要和其他内网机器通信,所以需要配置内网ip的路由地址。整个操作过程,记录如下,以供以后参考学习:
1)内网网卡绑定 [root@external-lb01 ~]# cd /etc/sysconfig/network-scripts/ [root@external-lb01 network-scripts]# cat ifcfg-em1 DEVICE=em1 HWADDR=80:18:44:EB:0F:F4 TYPE=Ethernet UUID=1bb1d77b-2cda-4640-b425-3ef692138937 ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none MASTER=bond0 SLAVE=yes [root@external-lb01 network-scripts]# cat ifcfg-em2 DEVICE=em2 HWADDR=80:18:44:EB:0F:F5 TYPE=Ethernet UUID=e28f73ac-9149-47d9-84eb-3e7c027038e2 ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none MASTER=bond0 SLAVE=yes [root@external-lb01 network-scripts]# cat ifcfg-bond0 DEVICE=bond0 name='bond0' TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none IPADDR=10.0.36.21 NETMASK=255.255.255.0 GATEWAY=10.0.36.1 BONDING_OPTS='mode=4 miimon=100' 2)外网网卡绑定 [root@external-lb01 network-scripts]# cat ifcfg-em3 DEVICE=em3 HWADDR=80:18:44:EB:0F:F6 TYPE=Ethernet UUID=4f0384bb-7140-4161-9a87-561e0964120c ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none MASTER=bond1 SLAVE=yes [root@external-lb01 network-scripts]# cat ifcfg-em4 DEVICE=em4 HWADDR=80:18:44:EB:0F:F7 TYPE=Ethernet UUID=2e9236cb-4745-46b7-bfb7-9bf7333fd99a ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none MASTER=bond1 SLAVE=yes [root@external-lb01 network-scripts]# cat ifcfg-bond1 DEVICE=bond1 name='bond1' TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none IPADDR=115.182.11.21 NETMASK=255.255.255.240 GATEWAY=115.182.11.17 BONDING_OPTS='mode=4 miimon=100' 3)修改网卡绑定配置 [root@external-lb01 network-scripts]# cat /etc/modprobe.d/bonding.conf alias bond0 bonding options bonding mode=4 miimon=100 alias bond1 bonding options bonding mode=4 miimon=100 网卡绑定生效: [root@external-lb01 network-scripts]# modprobe bonding [root@external-lb01 network-scripts]# /etc/init.d/network restart [root@external-lb01 network-scripts]# modprobe bonding 查看网卡绑定结果: [root@external-lb01 network-scripts]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: IEEE 802.3ad Dynamic link aggregation Transmit Hash Policy: layer2 (0) MII Status: up ........ ........ [root@external-lb01 network-scripts]# cat /proc/net/bonding/bond1 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: IEEE 802.3ad Dynamic link aggregation Transmit Hash Policy: layer2 (0) MII Status: up ........ ........ 4)查看路由 [root@external-lb01 ~]# route -n //默认配置了外网网关地址 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 115.182.11.16 0.0.0.0 255.255.255.240 U 0 0 0 bond1 10.0.36.0 0.0.0.0 255.255.255.0 U 0 0 0 bond0 169.254.0.0 0.0.0.0 255.255.0.0 U 1006 0 0 bond0 169.254.0.0 0.0.0.0 255.255.0.0 U 1007 0 0 bond1 0.0.0.0 115.182.11.17 0.0.0.0 UG 0 0 0 bond1 [root@external-lb01 ~]# cat /etc/resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 如上配置后,该机器可以ping通别的机器,及网络出去没有问题,因为配置了外网地址。 但是别的内网机器ping不通该机,这就需要配置该机的内网网关。 5)设置内网网关 临时设置内网网关(重启网卡服务后,这个临时设置的网关地址就消失了) [root@external-lb01 ~]# route add -net 10.0.0.0/8 gw 10.0.36.1 永久设置内网网关(这样重启网卡服务后,这个网关地址还会在) [root@external-lb01 ~]# vim /etc/sysconfig/network GATEWAY=10.0.36.1 [root@external-lb01 ~]# vim /etc/sysconfig/static-routes any net 10.0.0.0/8 gw 10.0.36.1 开启IP转发 [root@external-lb01 ~]# echo "1" >/proc/sys/net/ipv4/ip_forward //临时开启 [root@external-lb01 ~]# vim /etc/sysctl.conf net.ipv4.ip_forward = 1 //永久开启 重启网卡 [root@external-lb01 ~]# /etc/init.d/network restart