红联Linux门户
Linux帮助
当前位置: 红联Linux门户 > Debian

用debian的iptables做简单路由(双网卡)

发布时间:2008-03-22 00:02:06来源:红联作者:jsbxw
1.在/etc/rc.d/rc.local中加入如下

(1).如果是DHCP直接上网
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j MASQUERADE

(2).如果是ADSL拨号上网
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.1.0/24 -j MASQUERADE

(3).如果是固定IP

iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j SNAT -to-source 10.4.40.13(固定IP)

2./etc/network/interfaces文件配置
# 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

auto dsl-provider
iface dsl-provider inet ppp
pre-up /sbin/ifconfig eth1 up # line maintained by pppoeconf
provider dsl-provider

auto eth1
iface eth1 inet manual

auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0

3.配置客户机网卡
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1

如果在上面的服务器下再接一个服务器,配置于上面基本相同,例如:

1.同上(略)

2.配置外网的网卡
iface eth0 inet static
address 192.168.1.133
netmask 255.255.255.0
gateway 192.168.1.1 //指定上一台服务器IP

3.配置内网的网卡
iface eth1 inet static
address 192.168.1.134
netmask 255.255.255.0

4.配置其它客户机网卡
iface eth0 inet static
address 192.168.1.135
netmask 255.255.255.0
gateway 192.168.1.133 //网关
文章评论

共有 0 条评论