阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

iptables之实现SNAT

167次阅读
没有评论

共计 1095 个字符,预计需要花费 3 分钟才能阅读完成。

0、简介
在小型的网络环境中,不需要购买额外的路由器设备来实现连接外网,可以使用 linux 中的 iptables 防火墙来实现连接 Internet

一、拓扑图

iptables 之实现 SNAT

具体的配置:
※RedHat(5.8)
1. 开启路由转发功能

#echo 1 >/proc/sys/net/ipv4/ip_forward
#sysctl -a | grep “ip_forward”
显示“net.ipv4.ip_forward=1”即可表示成功开启,该方法只是临时有效,重启就会失效
永久生效方式,则需要将“net.ipv4.ip_forwaed=1”写入 /etc/sysctl.conf 中,“sysctl -p”生效

2. 配置 iptables 的 SNAT 规则
①外网使用的是静态的 ip

iptables -t  nat -A  POSTROUTING -s 192.168.1.0/24 -o eth0  -j  SNAT –to-source 202.100.1.1
语法:
iptables -t nat -A POSTROUTING -s source_ip  -o  interface_output -j SNAT –to-source ip[-ip]:[port-port]

②如果是动态获取 ip+ADSL 拨号则使用

iptables -t  nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0  -j MASQUERADE

※www-server

yum  install -y  httpd
echo “jeffery.com’s home page” > /var/www/html/index.html
service httpd start
setenforce 0  ## 关闭 selinux
iptables -F    ## 做测试,防火墙可关闭

※w2003 只需要配置好 ip 地址和 gw 即可

测试:

iptables 之实现 SNAT

推荐阅读:

iptables—包过滤(网络层)防火墙 http://www.linuxidc.com/Linux/2013-08/88423.htm

Linux 防火墙 iptables 详细教程 http://www.linuxidc.com/Linux/2013-07/87045.htm

iptables+L7+Squid 实现完善的软件防火墙 http://www.linuxidc.com/Linux/2013-05/84802.htm

iptables 的备份、恢复及防火墙脚本的基本使用 http://www.linuxidc.com/Linux/2013-08/88535.htm

Linux 下防火墙 iptables 用法规则详解 http://www.linuxidc.com/Linux/2012-08/67952.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计1095字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中