Redirecting traffic (localhost to remote) linux

Опубликовано: 06 Июнь 2026
на канале: mrwhitep
142
7

set the parameter on the kernel

sysctl -w net.ipv4.conf.all.route_localnet=1

NOTE: You can make it persistent by adding net.ipv4.conf.all.route_localnet=1 under /etc/sysctl.conf and run the command sysctl -p


Adding the firewall rules


firewall-cmd --add-masquerade --perm
firewall-cmd --direct --add-rule ipv4 nat OUTPUT 0 -d 127.0.0.1 -p tcp --dport 8443 -j DNAT --to-destination 192.168.1.6:8443


You can check the redirected rule like this

firewall-cmd --direct --get-all-rules


You can remove it by running the following command
firewall-cmd --direct --remove-rule ipv4 nat OUTPUT 0 -d 127.0.0.1 -p tcp --dport 8443 -j DNAT --to-destination 192.168.1.6:8443



Test it

curl -vvv http://127.0.0.1:8443
telnet 127.0.0.1:8443
elinks http://127.0.0.1:8443