CentOS双网卡双IP设置
日期:2017-03-13
CentOS双网卡双ip设置
系统环境:CentOS Linux
网络环境:两个IP地址192.168.0.2和192.168.1.2,掩码是255.255.255.0,
这两个子网的网关地址分别是192.168.0.1和192.168.1.1。
1.配置网卡ip,cd /etc/sysconfig/network-scripts/ 进入网卡目录
vi ifcfg-eth0 编辑网卡0
DEVICE="eth0"
HWADDR="00:0C:29:6C:BB:E6"
NM_CONTROLLED="yes"
ONBOOT="yes"
IPADDR=192.168.0.2
NETMASK=255.255.255.0
BOOTPROTO=static
vi ifcfg-eth1 编辑网卡1
DEVICE="eth1"
HWADDR="00:0C:29:6C:BB:E7"
NM_CONTROLLED="yes"
ONBOOT="yes"
IPADDR=192.168.1.2
NETMASK=255.255.255.0
BOOTPROTO=static
2,配置默认网关
vi /etc/sysconfig/network 设置网关
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.0.1
GATEWAY=192.168.1.1
3,编辑路由表
vi /etc/init.d/network 在末尾添加路由
ip route flush table line1
ip route add default via 192.168.0.1 dev eth0 src 192.168.0.2 table line1
ip rule add from 192.168.0.2 table line1
ip route flush table line2
ip route add default via 192.168.1.1 dev eth1 src 192.168.1.2 table line2
ip rule add from 192.168.1.2 table line2
wq!保存退出
vi /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
252 line1 //设置优先级
251 line2 //设置优先级
0 unspec
#
# local
#
#1 inr.ruhep
vi /etc/reslov.conf 设置DNS
nameserver 223.5.5.5
nameserver 223.6.6.6
service network restart 重启网卡服务
ping www.baidu.com
PING www.a.shifen.com (180.97.33.107) 56(84) bytes of data.
64 bytes from 180.97.33.107: icmp_seq=1 ttl=54 time=6.02 ms
64 bytes from 180.97.33.107: icmp_seq=2 ttl=54 time=6.05 ms
64 bytes from 180.97.33.107: icmp_seq=3 ttl=54 time=6.05 ms
64 bytes from 180.97.33.107: icmp_seq=4 ttl=54 time=6.03 ms
64 bytes from 180.97.33.107: icmp_seq=5 ttl=54 time=6.09 ms
64 bytes from 180.97.33.107: icmp_seq=6 ttl=54 time=6.03 ms
64 bytes from 180.97.33.107: icmp_seq=7 ttl=54 time=6.10 ms
64 bytes from 180.97.33.107: icmp_seq=8 ttl=54 time=5.98 ms
64 bytes from 180.97.33.107: icmp_seq=9 ttl=54 time=6.02 ms
64 bytes from 180.97.33.107: icmp_seq=10 ttl=54 time=6.04 ms
64 bytes from 180.97.33.107: icmp_seq=11 ttl=54 time=6.12 ms
64 bytes from 180.97.33.107: icmp_seq=12 ttl=54 time=6.09 ms
64 bytes from 180.97.33.107: icmp_seq=13 ttl=54 time=6.07 ms
64 bytes from 180.97.33.107: icmp_seq=14 ttl=54 time=6.14 ms
64 bytes from 180.97.33.107: icmp_seq=15 ttl=54 time=6.04 ms
64 bytes from 180.97.33.107: icmp_seq=16 ttl=54 time=6.01 ms
^C
--- www.a.shifen.com ping statistics ---
16 packets transmitted, 16 received, 0% packet loss, time 15052ms
rtt min/avg/max/mdev = 5.982/6.058/6.142/0.104 ms
route 查看路由
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth1
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
link-local * 255.255.0.0 U 1003 0 0 eth1
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth1