debian做网关的简单设置

来源:互联网 发布:花样年华观后感知乎 编辑:程序博客网 时间:2024/05/22 03:45

1、网关主机设置

eth0为外网网卡, eth1是内网网卡。

(1) 修改/etc/network/interfaces文件内容如下:

auto lo eth0 eth1

iface lo inet loopback

allow-hotplug eth0

iface eth0 inet static
address 172.16.21.1
netmask 255.255.0.0
gateway 172.16.1.1


iface eth1 inet static
address 192.168.0.1
netmask 255.255.255.0

当然也可以使用ifconfig进行配置:
$ ifconfig eth0 172.16.21.1 netmask 255.255.0.0
$ route add default gw 172.16.1.1
$ ifconfig eth1 192.168.0.1 netmask 255.255.255.0

(2) echo "1" > /proc/sys/net/ipv4/ip_forward
或修改/etc/sysctl.conf,加上net.ipv4.ip_forward = 1

(3) iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE


(4)修改DNS服务器配置文件: /etc/resolv.conf

//具体DNS地址依据ISP提供设置
nameserver 202.102.134.68
nameserver 202.102.128.68


修改完成后,/etc/init.d/networking restart重新启动。

2、IP伪装(IP-masquerade)

这时将lan内主机网关改为192.168.0.1,应该能ping通该网关,但是还是连不上internet。要实现LAN内的机器通过共享一个单独的可访问外网的IP地址来访问Internet资源,还需要在网关上安装ipmasq。

$ sudo apt-get install ipmasq

会提示进行一些设置,都默认即可。之后lan内主机应该就能连上internet了。

原创粉丝点击