免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1150 | 回复: 0
打印 上一主题 下一主题

linux adsl 共享上网 、 nat 及动态域名的设置方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-24 17:27 |只看该作者 |倒序浏览

一、系统及adsl 配置
     redhat 系统两快网卡
eth0 192.168.1.1
eth1 192.168.0.1
eth0 连接adsl 猫.
任务: 使用gnway 的动态域名软件把内网的几台服务器发布出去.
使用 adsl-setup 设置adsl (可以搜索linux adsl 设置方法)
#adsl-start 后
#ifconfig -a 查看ppp0 是否连上
二、adsl 拨号及共享脚本
pp.sh  adsl 启动及共享连接
adsl-stop
adsl-start
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.1/24 -j MASQUERADE

三、nat 脚本
tnat 文件, 将adsl外部地址的80 , 8088 端口分别映射到 192.168.0.105 的8083 及 8088 端口上
iptables -t nat -F PREROUTING
iptables -t nat -F POSTROUTING
iptables -A POSTROUTING -t nat -o ppp0 -j MASQUERADE
perl mnat.pl 80 192.168.0.105 8083
perl mnat.pl 8088 192.168.0.105 8088

mnat.pl 文件, 简化影射命令的perl 文件
system("rm -rf tmp.txt");
system("ifconfig ppp0 >> tmp.txt");
open(FILE1,"tmp.txt") || die "Couldn't open tmp.txt";
@num1 = ;
my $cmdstr = $num1[1];
my $pos = index($cmdstr,"inet addr:");
$cmdstr = substr($cmdstr,$pos+10);
$pos = index($cmdstr," ");
$cmdstr = substr($cmdstr,0,$pos);
my $interip = $cmdstr;

my $localip = $ARGV[1]; # local host ip
my $localport = $ARGV[2]; # local host port
my $interport = $ARGV[0]; # internet port

$cmdstr1 ="iptables -t nat -A PREROUTING -p tcp -m tcp -d ".$interip." --dport ".$interport." -j DNAT --to-destination 192.168.0.105:".$localport."";
system($cmdstr1); # input port to dest localip
print $cmdstr1;
$cmdstr1 = "iptables -t nat -A POSTROUTING -p tcp -m tcp -d ".$localip." --dport ".$localport." -j SNAT --to-source ".$interip;
system($cmdstr1); # output to gateway
print $cmdstr1;
close(FILE1);
system("rm -f tmp.txt");

三、动态域名系统
www.gnway.net
下载 gnhostlinux1.3.2.tar
mkdir gn
mv gnhostlinux1.3.2.tar gn
cd gn
tar -zxvf gnhostlinux1.3.2.tar
执行 ./install.sh 安装
编辑
/etc/gnhostlinux.conf
USERNAME=gnhost 用户名
PASSWORD=gnhost 密码
运行
/etc/init.d/gnhostlinuxd restart
即可启动动态域名服务
可将
pp.sh
tnat
/etc/init.d/gnhostlinuxd restart
加入 /etc/rc.d/rc.local 即可实现开机自动运行。




本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4831/showart_470823.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP