Ubuntu 将两张网卡的ubuntu配置成路由器

eth0      Link encap:Ethernet  HWaddr 40:16:9f:f0:fc:10  
          inet addr:192.168.1.18  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::4216:9fff:fef0:fc10/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:637 errors:0 dropped:0 overruns:0 frame:0
          TX packets:591 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:632116 (632.1 KB)  TX bytes:60416 (60.4 KB)

eth1      Link encap:Ethernet  HWaddr 50:e5:49:14:0d:95  
          inet addr:172.17.64.228  Bcast:172.17.65.255  Mask:255.255.254.0
          inet6 addr: fe80::52e5:49ff:fe14:d95/64 Scope:Link
          inet6 addr: 2001:db8::6ccd:b1a3:c799:25e/64 Scope:Global
          inet6 addr: 2001:db8::52e5:49ff:fe14:d95/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:29201 errors:0 dropped:3488 overruns:0 frame:0
          TX packets:3022 errors:0 dropped:0 overruns:0 carrier:1
          collisions:0 txqueuelen:1000
          RX bytes:4318829 (4.3 MB)  TX bytes:364085 (364.0 KB)

 

172.16.100.7, 172.16.100.9, 172.16.100.8, 172.17.198.32

1.sudo apt-get remove network-manager
   sudo vim /etc/network/interfaces

  auto lo
 iface lo inet loopback
auto eth1
iface eth1 inet static
address 192.168.168.137
gateway 192.168.168.1
netmask 255.255.255.0
dns-nameservers 114.114.114.114

auto eth1:1
iface eth1:1 inet static
address 172.16.184.210
netmask 255.255.255.0

auto eth0
iface eth0 inet static
address 192.168.1.12
netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
address 192.168.0.1
netmask 255.255.255.0

重启,使相关配置生效 sudo /etc/init.d/networing restart

2. 配置使系统具备路由功能
    sudo vim /etc/sysctl.conf
    net.ipv4.ip_forward=1
    重启配置, 使生效sudo sysctl -p。

3. 添加NAT条目
   sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
   -s source network
   -o dest netwok card
  
    注, 第三步添加NAT条目的配置在重启后就会消失,应重新添加或写脚本在启动时就添加。

    若要求永久生效, 则按下列步骤。
    sudo vim /etc/init.d/nat
    添加  sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
    sudo chmod 777 /etc/init.d/nat
    sudo ln -s /etc/init.d/nat /etc/rcS.d/S42nat

转载于:https://www.cnblogs.com/gavinwu/p/3471570.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值