UBuntu8.04 Server设置路由器
Linux作为路由器的好处是相比专业的路由器设备,费用节省很多,因为硬件通常都是使用旧电脑加上几块网卡,而Linux系统有很多免费的可以使用。并且由于可以自己定制,可以针对企业网络的情况指定灵活的网络管理规则。但是这种做法需要学习很多知识,往往令人生畏。本文总结了自己的个人经验,试图帮助更多的Linux爱好者。
我的设置路由器的方法主要用到了UBuntu设置网卡地址、route命令和iptables的相关知识。用eth0直接连接在Internet上,另外两个通过IP包转发的方式和其他子网通信并因此可以连接Internet。
File Edit Options Buffers Tools Help
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 58.246.17.2
netmask 255.255.255.248
network 58.246.17.0
broadcast 58.246.17.7
gateway 58.246.17.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 210.22.70.3
dns-search longday.com
# The sencond network interface
auto eth1
iface eth1 inet static
address 192.168.10.244
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255
gateway 192.168.10.244
#dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.10.244
编辑好上面的文件后,执行sudo /etc/init.d/networking restart 重启网络服务。
修改/etc/resolv.conf文件下的DNS为210.22.70.3,重启计算机。
1)所有发往58.246.17.0网段的数据包经过eth0网卡
2)所有发往192.168.10.0网段的数据包经过eth1网卡
route命令可以用来查看当前路由表的设置,route del用于删除某条路由设置,route add用于添加某条路由设置.最后设置好的路由表如下:
/etc/network # route
Kernel IP routing table
Destination Gateway Genmask
我的设置路由器的方法主要用到了UBuntu设置网卡地址、route命令和iptables的相关知识。用eth0直接连接在Internet上,另外两个通过IP包转发的方式和其他子网通信并因此可以连接Internet。
设置网卡
首先给我的三块网卡分配不同的地址:(通过sudo身份编辑/etc/network/interfaces文件)文件内容如下:File Edit Options Buffers Tools Help
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 58.246.17.2
netmask 255.255.255.248
network 58.246.17.0
broadcast 58.246.17.7
gateway 58.246.17.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 210.22.70.3
dns-search longday.com
# The sencond network interface
auto eth1
iface eth1 inet static
address 192.168.10.244
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255
gateway 192.168.10.244
#dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.10.244
编辑好上面的文件后,执行sudo /etc/init.d/networking restart 重启网络服务。
修改/etc/resolv.conf文件下的DNS为210.22.70.3,重启计算机。
设置路由
现在我们要通过route命令设置路由,使得:1)所有发往58.246.17.0网段的数据包经过eth0网卡
2)所有发往192.168.10.0网段的数据包经过eth1网卡
route命令可以用来查看当前路由表的设置,route del用于删除某条路由设置,route add用于添加某条路由设置.最后设置好的路由表如下:
/etc/network # route
Kernel IP routing table
Destination Gateway Genmask