centos系统配置端口转发(价值20)

firewall 端口转发
CentOS 7.0以上使用的是firewall,通过命令行配置实现端口转发。
(1)开启伪装IP
firewall-cmd --permanent --add-masquerade
(2)配置端口转发,将到达本机的12345端口的访问转发到另一台服务器的22端口。
firewall-cmd --permanent --add-forward-port=port=12345:proto=tcp:toaddr=192.168.172.131:toport=22
(3)重新载入,使其生效。
firewall-cmd --reload

实战:

   13  firewall-cmd --add-masquerade --permanent
   14  firewall-cmd --add-forward-port=port=80:proto=tcp:toport=80:toaddr=103.236.240.72 --permanent
   15  firewall-cmd --add-forward-port=port=3306:proto=tcp:toport=3306:toaddr=103.236.240.72 --permanent
   16  firewall-cmd --add-forward-port=port=20013:proto=tcp:toport=20013:toaddr=103.236.240.72 --permanent
   17  firewall-cmd --add-forward-port=port=20021:proto=tcp:toport=20021:toaddr=103.236.240.72 --permanent
   18  firewall-cmd --add-forward-port=port=8089:proto=tcp:toport=8089:toaddr=103.236.240.72 --permanent
   19  firewall-cmd --add-forward-port=port=8001:proto=tcp:toport=8001:toaddr=103.236.240.72 --permanent
   20  firewall-cmd --add-forward-port=port=1888:proto=tcp:toport=1888:toaddr=103.236.240.72 --permanent
   21  firewall-cmd --add-forward-port=port=18888:proto=tcp:toport=18888:toaddr=103.236.240.72 --permanent
   22  firewall-cmd --add-forward-port=port=9001:proto=tcp:toport=9001:toaddr=103.236.240.72 --permanent
   23  firewall-cmd --add-forward-port=port=5007:proto=tcp:toport=5007:toaddr=103.236.240.72 --permanent
   24  firewall-cmd --add-forward-port=port=8181:proto=tcp:toport=8181:toaddr=103.236.240.72 --permanent
   25  firewall-cmd --add-forward-port=port=5622:proto=tcp:toport=5622:toaddr=103.236.240.72 --permanent
   26  firewall-cmd --add-forward-port=port=10001:proto=tcp:toport=10001:toaddr=103.236.240.72 --permanent
   27  firewall-cmd --add-forward-port=port=11001:proto=tcp:toport=11001:toaddr=103.236.240.72 --permanent
   28  firewall-cmd --add-forward-port=port=11002:proto=tcp:toport=11002:toaddr=103.236.240.72 --permanent
   29  firewall-cmd --add-forward-port=port=7001:proto=tcp:toport=7001:toaddr=103.236.240.72 --permanent

   
firewall-cmd --add-forward-port=port=818:proto=tcp:toport=818:toaddr=58.218.66.113 --permanent
firewall-cmd --add-forward-port=port=88:proto=tcp:toport=88:toaddr=103.236.240.72 --permanent

firewall-cmd --permanent --zone=public --remove-forward-port=port=88:proto=tcp:toaddr=58.218.66.113:toport=88 --删除转发规则 
firewall-cmd --permanent --zone=public --remove-forward-port=port=88:proto=tcp:toaddr=103.236.240.72:toport=88 --删除转发规则 

systemctl restart firewalld.service

firewall-cmd --list-all

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=80:toaddr=58.218.66.113 --permanent


---数据库转发
firewall-cmd --add-forward-port=port=3307:proto=tcp:toport=3306:toaddr=103.236.240.81 --permanent
systemctl restart firewalld.service
firewall-cmd --list-all

iptables 端口转发
CentOS 7.0 以下使用的是iptables,可以通过iptables实现数据包的转发。

(1)开启数据转发功能
vi /etc/sysctl.conf   
  #增加一行 net.ipv4.ip_forward=1
//使数据转发功能生效
sysctl -p
(2)将本地的端口转发到本机端口
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j REDIRECT --to-port 22
(3)将本机的端口转发到其他机器
iptables -t nat -A PREROUTING -d 192.168.172.130 -p tcp --dport 8000 -j DNAT --to-destination 192.168.172.131:80
iptables -t nat -A POSTROUTING -d 192.168.172.131 -p tcp --dport 80 -j SNAT --to 192.168.172.130

#清空nat表的所有链
iptables -t nat -F PREROUTING

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值