1

I know you can't put a port in /etc/hosts, so how can I achieve the equivalent of:

127.0.0.1     https://website.com:4433

For WordPress, I need CURL to go to 127.0.0.1 on port 4433. As it's wordpress and not a script I made, I can't change that.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
user8292439
  • 3,808

3 Answers3

3

I managed to find the iptables rule to fix my issue:

iptables -A OUTPUT -d 127.0.0.1/32 -p tcp -j DNAT --to-destination 127.0.0.1:4433
user8292439
  • 3,808
2

Add a line into your /etc/hosts:

127.0.0.1      website.com

then configure your program (whatever it is) to listen on 4433 at 127.0.0.1.

And you're done.


Example:

echo hi | nc -lt 127.0.0.1 4433

now open website.com:4433 and you should see a "hi".

to fix the problem you mentioned in the comments you can use socat:

socat tcp-listen:4433,reuseaddr,fork tcp:localhost:xx

with the above command, socat will listen on 4433 and whenever a request came in in will forward it to the xx, so change the xx with the real port where your program is listening to.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
0

If you use the Chrome web browser, they have a URL aliasing app. It's called URL Alias. Just load it and define a web site. In the definition, you can add the full URL with port designation.