实战 Ubuntu电信网通双线双IP双网卡配置

本文介绍如何在双线机房中配置Web服务器,使其能够同时接入电信和网通线路,并实现智能解析。具体步骤包括网络接口配置、路由表设置等。

公司的Web服务器搬到了双线机房,同时接了电信和网通两根线,各自有各自IP地址。

域名通过DNSPod (https://www.dnspod.com/,在此特别感谢dnspod)做了智能解析

服务器配置如下:

The everonment:
Server Ubuntu 8.04 server
TEL IP: 222.73.178.212 netmask:255.255.255.128  gateway:222.73.178.129
CNC IP: 112.65.242.60  netmask:255.255.255.240  gateway:112.65.242.49

1.configure the network
$ sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 222.73.178.212
        netmask 255.255.255.128
        #network 211.152.56.128
        #broadcast 211.152.56.255
        gateway 222.73.178.129
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 202.96.209.133
        dns-search bucu

auto eth1
iface eth1 inet static
        address 112.65.242.60
        netmask 255.255.255.240

Save and exit and the restart the network
$ sudo /etc/init.d/networking restart

Add two route tables for tel and cnc
$ sudo vim /etc/iproute2/rt_tables
252 tel
251 cnc

Save and exit
Add route rule
$ sudo ip route flush table tel
$ sudo ip route add default via 222.73.178.129 dev eth0 src 222.73.178.212 table tel
$ sudo ip route add from 222.73.178.212 table tel

$ sudo ip route flush table cnc
$ sudo ip route add default via 112.65.242.49 dev eth1 src 112.65.242.60 table cnc
$ sudo ip rule add from 112.65.242.60 table cnc

Add the commands above to networking start file
$ sudo vim /etc/init.d/networking
ip route flush table tel
ip route add default via 222.73.178.129 dev eth0 src 222.73.178.212 table tel
ip rule add from 222.73.178.212 table tel

ip route flush table cnc
ip route add default via 112.65.242.49 dev eth1 src 112.65.242.60 table cnc
ip rule add from 112.65.242.60 table cnc

exit 0

 

参考资料:

http://www.lukexp.com/?p=10

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在企业网络场景中,常需一台计算机同时连接内外网并实现数据转发。本文将指导如何在 Ubuntu中完成双网卡配置及内外网路由转发。 确保 Ubuntu已安装,且备额外物理网卡用于连接另一网络。 为更好地控制网络配置,需关闭 Network Manager 服务。在终端执行命令: 关闭后,图形界面网络配置失效,需手动配置 IP息。 设定: eth0 为外网网卡; eth1 为内网网卡。 编辑 /etc/network/interfaces 文件,命令: 按以下格式配置: 注意,gateway 仅针对 eth1,因数据包需经其转发至外网。 配置完成后,重启网络服务使更改生效: 使用命令 route -n 查看路由表是否正确配置: 确认 eth0 和 eth1 的路由息已正确添加。 开启 IP 转发: 清除现有 iptables 规则: 允许数据包通过: 配置 NAT: 可使用命令 iptables -t nat -L POSTROUTING 检查 NAT 规则是否正确添加。 若需实现内外网无缝连接,可构建网桥。需先安装 bridge-utils 包: 安装完成后: 创建网桥:brctl addbr br0 添加网卡到网桥:brctl addif br0 eth0 和 brctl addif br0 eth1 配置网桥 IP 地址:编辑 /etc/network/interfaces 文件 重启网络服务:sudo /etc/init.d/networking restart 至此,Ubuntu 双网卡配置及内外网路由转发完成,可满足不同网络环境中的数据转发需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值