Hosts file with port?
19,961
Solution 1
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
Solution 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.
Related videos on Youtube
Author by
NerdOfLinux
Updated on September 18, 2022Comments
-
NerdOfLinux almost 2 years
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.
-
NerdOfLinux almost 7 yearsI can't tell the program to listen on 4433
-
Rinzwind almost 7 yearswhy can't you tell curl to listen to port 4433?
-
NerdOfLinux almost 7 yearsIt's part of wordpress. I have a problem with WP-cron and I need it to redirect my domain name to localhost.
-
Ravexina almost 7 yearsThat's another question however I'll update my answer ;)
-
NerdOfLinux almost 7 yearsIs there an iptables rule to redirect localhost requests to port 443 to port 4433?
-
Run almost 5 yearsThis doesn't show any 'website.com' information.