admin管理员组

文章数量:1642341

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

本文标签: 端口价值系统配置CENTOS