I have situation where my customer shutting down his old Linux host(examplehost01.example.com) which runs an application listening on the port 7001, where he created the new Server and they want to move all the traffic to new Server(examplehost02.example.com).

examplehost01.example.com: 7001 (old Server)
examplehost02.example.com: (New Server)

How we can redirect all the traffic on examplehost01.example.com Server on port 7001 to new Server examplehost02.example.com at port 7001?

These Servers are in the same network.

any help would be much appreciated.

  • More information about the network setup is required. Are the two hosts in the same network? Is it possible to route the IP address from the old host to the new host?
    – Dylan
    Jun 24, 2022 at 11:32
  • Its in the same network.
    – user294110
    Jun 24, 2022 at 11:38

3 Answers 3


Server migrations are when you discover what name people really are using for the server.

Create in DNS a service name for this, say examplething.example.com Which is not a specific host, but the frontend of this application.

Create CNAME records or otherwise point it to examplehost02. This would be the opportunity to introduce a load balancer or high availability cluster, if your design includes that.

Reconfigure all clients to point to the permanent service name examplething.example.com. Explain that the server is being replaced to maintain performance and availability of the system. And that as a part of this application focused approach, you now wish to make the name outlast any one server.

Keep the old name and IP for compatibility. Such as assigning the 01 IP to the 02 server. Set an end date for when it will be retired and the old examplehost01 name removed. Record connections to the old IP, such as with firewall logging rules, to find remaining not migrated clients.


Since both hosts are in the same network, the IP address of the old host can be assigned to the new host as a secondary IP. Then, an internal redirection can be configured to redirect traffic sent to oldip:7001 to port 80 or 443.


All methods described below are applicable even if servers are placed far away. However, if they're close, like that in the same subnet, there are better ways to do the thing.

Simple DNAT wouldn't work, because it would require routing all traffic from the other server (examplehost02) via this one (examplehost01), or setting up a complex routing setup. However, you may do both DNAT and SNAT at once. This has a caveat: the traffic redirected this way will appear on the other server as coming from this one; if this is unacceptable, you have to use other method. However, this is the only generic method that will help your service is UDP.

For that, setup the following rules:

iptables -t nat -I PREROUTING -p tcp --dport 7001 -j DNAT --to-destination examplehost02.example.com
iptables -t nat -I POSTROUTING -p tcp --dport 7001 -d examplehost02.example.com -j MASQUERADE

If the service in question is HTTP-based, you may setup a reverse proxy. With proper logging setup, for the requests made through the proxy will be logged still the correct remote IP address, so it is applicable if previously announced caveat doesn't allow to use the method above.

The third possibility is to use SSH TCP port forwarding instead of address translation. It is simplest, but less performant, and it is also subject of the same caveat, and it also works only for TCP. For that, simply SSH from the old server to the new:

examlehost01# ssh examplehost02 -g -L 7001:localhost:7001

or vice versa, with reverse port forwarding (requires that the SSH server on examplehost01 permits binding to the address, which may be not the default):

examlehost02# ssh examplehost01 -g -R 7001:localhost:7001

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .