要在Linux下使用PPPOE认证方式,必须安装PPPOE客户端软件。下面说明如何进行安装:
网卡配置。 两块网卡,eth1为拨号网卡,IP:192.168.1.254(其他的地址也可);eth0为内网网卡,IP:192.168.0.254.掩码均为255.255.255.0.局域网网段为192.168.0.0.
注意:此处两块网卡均不能设网关。 拨号(PPPOE)的网卡不用设置
2、 PPPoE软件的升级与安装
1) 在 http://www.roaringpenguin.com/pppoe/#download 下载
2) 安装rp-pppoe.以root身份执行
rpm –Uvh rp-pppoe-3.5-1.i386.rpm
3、 修改/etc/ sysctl.conf
将其中的
net.ipv4.ip_forward = 0
改为
net.ipv4.ip_forward = 1
4、 去除ipchains模块,只选择iptables方法如下:
1)setup
2)选择system service
3)去除ipchains
4)选中iptables
5)重启机器
5、 PPPoE客户端配置
在rp-pppoe-3.5-1.i386.rpm安装完毕后,接下来就可进行PPPoE客户端配置了。过程如下。
#/usr/sbin/adsl-setup
>;>;>; Enter your PPPoE user name: ——此处输入拨号帐号的用户名
>;>;>; 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
>;>;>; Enter the demand value (default no): ——输no
>;>;>; Enter the DNS information here: ——输210.52.149.2(视当地运营商的DNS服务器IP而定)
>;>;>; Please enter your PPPoE password: ——输网通用户口令
>;>;>; Choose a type of firewall (0-2): ——输0
>;>;>; Accept these settings and adjust configuration files (y/n)? ——输y
6、 启动拨号连接
/usr/sbin/adsl-start
成功连接后,屏幕显示Connected.
此时这台linux已可以上网浏览了。
注意:如果重启networdk服务 在ppp0起不来出现“/sbin/adsl-start: line 217: 4652 Terminated $CONNECT \"$@\" > /dev/null 2>&1” 错误 用如下命令 解决 setenforce 0 关闭selinux 关闭selinux 用如下方法也行
关闭SELinux认证
编辑 /etc/selinux/config文件,配置以下选项
SELINUX=disabled
然后执行以下命令使修改生效
# setenforce 0
7、 IP伪装
为了使局域网中的其他机器能通过Linux服务器共享上网,至少须执行下面的命令:
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
完成后,在192.168.0.0网段(网关为192.168.0.254)的PC机就可透过Linux上网了!
8、 开机自启动
为了使Linux服务器能够自动拨号,执行下面步骤。
1)chkconfig ——add adsl
2)setup
3)选择system services
4)选中ADSL
5)OK退出
6)打开/etc/rc.d/rc.local,在该文件的末尾添上下面语句
echo \"[OK]\"
echo \"Drop ICMP form anywhere\"
echo 1 >; /proc/sys/net/ipv4/icmp_echo_ignore_all
echo \"[OK]\"
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o ppp0 -j MASQUERADE
说明:前面四句用于关闭ICMP,防止别人Ping.
实现 内网端口映射 如公网IP地址是:114.243.240.128 访问114.243.240.128的8000端口 跳转到192.168.0.71:8000
如果有公网IP 则一条就可以
iptables -t nat -A PREROUTING -d 114.243.240.128 -p tcp --dport 8000 -j DNAT --to 192.168.0.71:8000
如果是拨号 则照下操作
1. 现在需要让公网上的机器访问外网卡的8000端口,并转发到192.168.0.71的8000端口
# service iptables stop
# vi /etc/rc.local
/bin/bash /usr/local/sbin/firewall
/bin/bash /usr/local/sbin/DNAT-IP &
# vi /usr/local/sbin/firewall
#! /bin/bash
WAN=$(ifconfig ppp0|grep \"inet\"|awk \'{print $2}\'|awk -F: \'{print $2}\')
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -F -t nat
iptables -X
iptables -X -t nat
iptables -P INPUT DROP
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A INPUT -i ppp0 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE
iptables -t nat -A PREROUTING -d $WAN -p tcp --dport 8000 -j DNAT --to 192.168.0.71:8000
# vi /usr/local/sbin/DNAT-IP
#! /bin/bash
while true
do
WAN=$(ifconfig ppp0|grep \"inet\"|awk \'{print $2}\'|awk -F: \'{print $2}\')
iptables -t nat -R PREROUTING 1 -d $WAN -p tcp --dport 8000 -j DNAT --to 192.168.0.71:8000
sleep 60
done
6. 将/etc/sysconfig/network-scripts/ifcfg-ppp0中的PPPOE_TIMEOUT=80,改为0,这样不会自动掉线
执行脚本 启动 iptables 就可以了。。
转载于:https://blog.51cto.com/lubing/910908