iptables: Duplicating/Forwarding ports

后端 未结 2 1276
别那么骄傲
别那么骄傲 2021-01-24 16:21

I\'m trying to connect to MySQL (Port 3306) from a network which blocks this port. But there is another port 110 open which I can use for this case. I\'m using MySQL for other a

相关标签:
2条回答
  • 2021-01-24 16:45

    When forwarding ports on ubuntu using iptables, you must:

    • make a backup of your firewall settings

    sudo iptables-save > iptables.backup

    • make sure the entry port is open

    sudo ufw allow 110/tcp

    • add a prerouting rule in your firewall

    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 110 -j REDIRECT --to-port 3306

    Notice the use of -i eth0. This routes port 110 to 3306 on network eth0. To check all connection of your machine, use ifconfig.
    If your machine is connected to multiple networks, you must use -i <network> or it will not work!

    • if you mess something up you can clean the NAT routing table with

    sudo iptables -F -t nat

    or restore iptables

    sudo iptables-restore < iptables.backup

    0 讨论(0)
  • 2021-01-24 16:50

    This might work, haven't tested it.

    iptables -t nat -A PREROUTING -p tcp --dport 110 -j REDIRECT --to-port 3306
    
    0 讨论(0)
提交回复
热议问题