当前位置:操作系统 > Unix/Linux >>

cs服务器的地址映射

用iptables做防火墙;iptables的配置文件:

  代码:

  for this to run iptables firewall

  #!/bin/sh

  /sbin/modprobe ip_tables

  /sbin/modprobe ip_nat_ftp

  /sbin/modprobe ip_conntrack_ftp

  /sbin/iptables -F

  /sbin/iptables -F -t nat

  /sbin/iptables -X

  /sbin/iptables -Z

  echo"1">/proc/sys/net/ipv4/ip_forward

  /sbin/iptables -P INPUT ACCEPT

  /sbin/iptables -P FORWARD ACCEPT

  /sbin/iptables -P OUTPUT ACCEPT

  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

  iptables -A FORWARD -s 0/0 -d 0/0 -j ACCEPT

  iptables -t nat -A PREROUTING -d (外网 ip不要端口) -p udp --dport 27015(这个地址无所谓) -j DNAT --to (内网地址不要端口)

  iptables -t nat -A POSTROUTING -d (内网地址) -p udp --dport 27015(端口就是内网cs服务器所用的端口启动脚本里面的那个+270xxx哪个) -o eth1 -j SNAT --to (内网网关)

  iptables -t nat -A POSTROUTING -s (内网地址) -p udp --dport 27010:27012 -o eth1 -j SNAT --to (内网网关)

  iptables -t nat -A POSTROUTING -s (内网地址) -p tcp --dport 5273 -o eth1 -j SNAT --to (内网网关)

  iptables -t nat -A POSTROUTING -s (内网地址) -p tcp --dport 7002 -o eth1 -j SNAT --to (内网网关)

  iptables -t nat -A POSTROUTING -s (内网地址) -p udp --dport 27010:27012 -o eth0 -j SNAT --to (外网地址)

  iptables -t nat -A POSTROUTING -s (内网地址) -p tcp --dport 5273 -o eth0 -j SNAT --to (外网地址)

  iptables -t nat -A POSTROUTING -s (内网地址) -p tcp --dport 7002 -o eth0 -j SNAT --to (外网地址)

  -p 指定协议(--protocol)

  --dport 指明端口(-- source-port/--sport和 --destination -port)

  -i 或者-o 指定网络接口(PREROUTING链用-i POSTROUTING 用-o)

  -s 指明源地址(--source/--src/源地址destination/--dst/目的地址)

  -A 加入一个新规则到一个链(一般写到最后面)(append)

  -I 在链内某个位置插入(insert)一般最后面

  -R 在链内某个位置替换一条规则

  -D 删除链内第一条规则(delete)

  -d 指明目的地址

  这样你的cs服务器就是外网ip:27015(其他的也可以)

  _________________

  代码:本文来自:http://www.xiaoyaxiao.com/1598.html
发表您的意见和建议!
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,