Centos+adsl+iptables

日期:2010-1-9
作者:frank
 
1、  网络配置:
Eth0 连接ADSL    eth1 连接局域网 
网卡配置如下:
[root@server network-scripts]# cat ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
HWADDR=00:21:27:9e:e3:49
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=192.168.3.3
[root@server network-scripts]# cat ifcfg-eth1
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth1
HWADDR=00:23:cd:92:b9:c2
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=192.168.0.31
NETWORK=192.168.0.0
 
2、配置PPPOE客户端软件 
Centos 默认安装了PPPOE 软件,直接配置
#adsl-setup     这个工具进行配置: 
>>> Enter your PPPoE user name : 
输入ADSL帐号的用户名 
>>> Enter the Ethernet interface connected to the ADSL modem 
For Solaris, this is likely to be something like /dev/hme0. 
For Linux, it will be ethn, where 'n' is a number. 
(default eth0): 
输入 eth0 ,这是ADSL相连的网卡的名字 
>>> Enter the demand value (default no): 
输入 no 
>>> Enter the DNS information here: 
输入 server ,这表示使用ADSL拨号自动获得的DNS服务器IP地址 
>>> Please enter your PPPoE password: 
输入ADSL帐号的密码 
>>> Choose a type of firewall (0-2): 
输入 2 ,使用防火墙 
>>> Accept these settings and adjust configuration files (y/n)? 
如果输入的信息正确,输入 y ,完成配置,否则,输入 n 重新输入。 
 
3、启动PPPOE客户端软件 
 
使用命令 
# adsl-start  启动PPPOE客户端软件,进行连接,如果成功,将出现 Connected; 如果不成功,请检查网线、ADSL MODEM等物理设备,并查看 /var/log/messages中的信息 
#adsl-stop 关闭和ISP的连接 
#adsl-status 查看当前连接的状态 
 
4、测试 
 
当连接成功后,使用命令 
[root@server ppp]# netstat -nr
Kernel IP routing table
Destination     Gateway    Genmask        Flags   MSS Window  irtt Iface
61.141.176.1    0.0.0.0    255.255.255.255 UH       0 0         0 ppp0
192.168.3.0     0.0.0.0    255.255.255.0   U         0 0          0 eth0
192.168.0.0     0.0.0.0    255.255.255.0   U         0 0          0 eth1
169.254.0.0     0.0.0.0    255.255.0.0     U         0 0          0 eth1
0.0.0.0         0.0.0.0     0.0.0.0         U         0 0          0 ppp0
看到最下面一行,应该就可以上网了。
 
5、设置共享上网
 
修改/etc/sysctl.conf,把net.ipv4.ip_forward设置成1,如下:
net.ipv4.ip_forward = 1
重新启动机器或重新启动网络服务(/etc/init.d/network restart)时就会自动启动ip转发功能!
 
也可以加入到自启文件中:rc.local
[root@server phlinux_install]# cat /etc/rc.d/rc.local
echo 1 >/proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o ppp0 -j ACCEPT
 
开机要自启动IPTABLES 不然会上不了网
Chkconfig iptables on
 
6iptables 设置:
 
我的如下:
[root@server phlinux_install]# iptables -n -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:20
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:21
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:25
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:53
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:110
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:53
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 139,445
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 137,138
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3000
 
Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 21,22,23,53,80,443,25,110,3389
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:53
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3000
 
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
 
[root@server phlinux_install]# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
 
7、结束
客户端网关要设为: 192.168.0.31  赶紧测试 OK 总算能上
重起linux 网关,其它机上网一切正常。