Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect port 443 (https) to IP using iptables

I've tried for some hours to do this simple job, but it is not so simple like you think.

I wanted to redirect every request for 443 and 80 port to a webserver , in my example http://127.0.0.1:80

Port 80 worked without any problems, but 443 port tried me a lot of time...

I guess you've tried already to run the following command:

iptables -t nat -A OUTPUT -p tcp -m tcp --dport 443 -j DNAT --to-destination 127.0.0.1:80

But this is wrong, because the port 443 cannot be redirected to other ports than 443.

like image 802
Carca Avatar asked Nov 01 '25 22:11

Carca


1 Answers

The solution is:

Use the following command:

iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to-destination 127.0.0.1:443

Then enable https for apache.

If you are using CentOS use this tutorial - http://wiki.centos.org/HowTos/Https

Good luck.

like image 118
Carca Avatar answered Nov 04 '25 06:11

Carca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!