Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used to run a service on port 25570 I'm now changing it to run on port 25565 but I still want people who try to access it on the old port to have access to the service. So I'd like to forward port 25570 to 25565 on the same machine.

I know there's a lot of questions that talk about forwarding to a different machine but I was wondering if the method is different when using the same machine?

share|improve this question
up vote 9 down vote accepted
iptables -t nat -A PREROUTING -p tcp --dport 25570 -j REDIRECT --to-port 25565

This assumes you're not routing traffic for an entire network through this box and that if you were there's no expectation that traffic destined for other hosts will be on that port

share|improve this answer

It is worth noting the the accepted answer only applies for other network hosts connecting to the machine running iptables. It does not redirect the port for clients running on the iptables machine trying to connect to port 25570 (for example).

These entries will forward the port for connections coming from the network or from the local host running the services.

sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443
sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport 443 -j REDIRECT --to-ports 8443
share|improve this answer
Thanks for this! Without this addition I wouldn't have been able to get my Vagrant box to request the site it was serving using the same port internally (to that of the host machine) i.e. HOST = localhost:9000 and now GUEST = localhost:9000 (which routes to :80) – Pebbl Sep 4 '15 at 10:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.