0

Would you please help me . I have a 2 vps (Ubuntu) I want to forward all traffic from one vps(1.1.1.1) to another (2.2.2.2) vps except ssh port on A vps(1.1.1.1) A server is 1.1.1.1 B server is 2.2.2.2

1st try:

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -i eth0 -d 1.1.1.1 -j DNAT --to 2.2.2.2
iptables -A FORWARD -i eth0 -d 1.1.1.1 -p tcp  --dport 22 -j REJECT
iptables -A FORWARD  -i eth0 -d 2.2.2 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

2nd try

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -j DNAT --to-destination 1.1.1.1
iptables -t nat -A PREROUTING -j DNAT --to-destination 2.2.2.2
iptables -t nat -A POSTROUTING -j SNAT

Both failed

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
Havard
  • 1
  • 1
  • What have you tried? How it failed? – Tero Kilkanen Nov 25 '22 at 21:06
  • sysctl net.ipv4.ip_forward=1 iptables -t nat -A PREROUTING -i eth0 -d 1.1.1.1 -j DNAT --to 2.2.2.2 iptables -A FORWARD -i eth0 -d 1.1.1.1 -p tcp --dport 22 -j REJECT iptables -A FORWARD -i eth0 -d 2.2.2 -j ACCEPT iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE – Havard Nov 25 '22 at 21:17
  • Please add additional information to the question by editing so that it is properly formatted. – Tero Kilkanen Nov 25 '22 at 21:18
  • sysctl net.ipv4.ip_forward=1 iptables -t nat -A PREROUTING -j DNAT --to-destination 1.1.1.1 iptables -t nat -A PREROUTING -j DNAT --to-destination 2.2.2.2 iptables -t nat -A POSTROUTING -j SNAT – Havard Nov 25 '22 at 21:18

0 Answers0