欢迎光临
我们一直在努力

NAT使用实例-网管专栏,防火墙和路由

建站超值云服务器,限时71元/月

#!/bin/sh

#####################################
# example nat usage for 2.4 kernels #
# stephanie lockwood-childs 1/17/01 #
#####################################

#———————-#
# variable definitions #
#———————-#

ext=eth0
int=eth1

# “masquerading” example
priv_nets=”128.111.1.1 128.111.185.0/255.255.255.0″
masq_net=192.168.1.0/255.255.255.0

# “general snat” example
map_from=192.168.1.0/255.255.255.0
map_to=128.111.185.30-128.111.185.42

# “redirection” example
internal_ip=10.10.1.1

# “port forwarding” example
external_ip=128.111.1.200
news_server=10.10.1.38
mail_server=10.10.1.69

# “load balancing” example
virtual_server=news.sblug.com
server_range=10.10.1.9-10.10.1.15

#————-#
# nat section #
#————-#

#
# flush previous rules
#

iptables -t nat -f

#
# masquerading
#

# masquerading for outgoing connections, except privileged nets are exempt
for net in $priv_nets ; do
iptables -t nat -a postrouting -d $net -o $ext -j accept
done
iptables -t nat -a postrouting -s $masq_net -o $ext -j masquerade

#
# general snat
#

# internal computers w/ private ips “borrow” public ips of other internal computers to ssh out
iptables -t nat -a postrouting -s $map_from -o $ext -p tcp –dport ssh -j snat –to-source $map_to
iptables -t nat -a postrouting -s $map_from -o $ext -p udp –dport ssh -j snat –to-source $map_to

#
# redirection
#

# redirect internal net http traffic through squid proxy, but allow direct access to local web server
iptables -t nat -a prerouting -i $int -d ! $internal_ip -p tcp –dport www -j redirect –to-port 8080

#
# port forwarding
#

# forward gateway port 7000 to news server and gateway port 8000 to pop mail server
iptables -t nat -a prerouting -d $external_ip -p tcp –dport 7000 -j dnat –to-dest $news_server:nntp
iptables -t nat -a prerouting -d $external_ip -p tcp –dport 8000 -j dnat –to-dest $mail_server:pop3

#
# load balancing
#

# basic load balancing by redirecting nntp requests to any of several local news servers
iptables -t nat -a prerouting -d $virtual_server -p tcp –dport nntp -j dnat –to-dest $server_range

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » NAT使用实例-网管专栏,防火墙和路由
分享到: 更多 (0)