V
V
vosyukov2020-01-10 23:52:56
linux
vosyukov, 2020-01-10 23:52:56

How to route traffic to VPS depending on the port?

There is a VPS that, depending on the port, traffic is redirected to other VPS.
For example, there is a vps with ip 1.1.1.1, game clients connect to it, let's say on port 7777 and 8888.
The task is to redirect traffic from port 7777 to one vps, and from port 8888 to another.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Talyan, 2020-01-11
@flapflapjack

iptables gallery?

ipables -A PREROUTING  -d VPS_IP/32 -i eth0 -p tcp -m tcp --dport 7777 -j DNAT --to-destination FIRST_IP:DST_PORT
ipables -A PREROUTING  -d VPS_IP/32 -i eth0 -p tcp -m tcp --dport 8888 -j DNAT --to-destination SECOND_IP_IP:DST_PORT

if your vps has ip 1.1.1.1, the servers have ip 2.2.2.2 and 3.3.3.3, respectively, and both of them have ports 9999, and the VPS interface that looks at the internet is eth0 then:
ipables -A PREROUTING  -d 1.1.1.1/32 -i eth0 -p tcp -m tcp --dport 7777 -j DNAT --to-destination 2.2.2.2:9999
ipables -A PREROUTING  -d 1.1.1.1/32 -i eth0 -p tcp -m tcp --dport 8888 -j DNAT --to-destination 3.3.3.3:9999

K
ky0, 2020-01-11
@ky0

In the standard way in the rules of the firewall.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question