CentOS双网卡、双IP配置实例

发布时间:2020-04-26编辑:脚本学堂
本文介绍下,在centos中配置双网卡、双IP的方法,有需要的朋友,作个参考吧。

如何在centos中配置双网卡、双IP环境呢?这里分享下我的操作实例。

系统环境:CentOS Linux
网络环境:
IP地址,192.168.0.10和10.10.30.2
掩码,255.255.255.0,
子网网关分别为:192.168.0.1和10.10.30.1。

1,为网卡eth0配置ip地址192.168.0.10,为网卡eth1配置ip地址为10.10.30.2配置文件为:

/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1

2,配置默认网关为任意一个。
此默认网关,决定了系统主动去使用网络时,使用的接口。
配置文件:/etc/sysconfig/network
3,编辑路由表 
修改/etc/iproute2/rt_tables,添加内容:
 

252   net2
251  net3
#/etc/rc.local 添加原路返回路由
ip route flush table net2
ip route add default via 192.168.0.1 dev eth0 src 192.168.0.10 table net2
ip rule add from 192.168.0.10 table net2
ip route flush table net3
ip route add default via 10.10.30.1 dev eth1 src 10.10.30.2 table net3
ip rule add from 10.10.30.2 table net3

就是这些了,在centos中配置双网卡、双IP,还是很简单的,希望对大家有所帮助。