Score:0

Port forwarding in Ubuntu 20.04 causes pings to fail

fm flag

I'm trying to forward ssh port to connect my servers together. Something like this:

Local Machine === (ssh) ===> Server A === (ssh) ===> Server B

My Servers aren't in a same location. They're both VPSs. My Local Machine IP address is dynamic.

I follow these steps:

  1. sysctl net.ipv4.ip_forward=1
  2. iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination SERVER_A
  3. iptables -t nat -A PREROUTING -j DNAT --to-destination SERVER_B
  4. iptables -t nat -A POSTROUTING -j MASQUERADE

After the 4th step my server seems to not to be able to connect to the internet anymore. For example my ping google.com will fails with error. ping: google.com: Temporary failure in name resolution

ping error after step 4

ping 8.8.8.8 works fine.

ping 8.8.8.8

Doug Smythies avatar
gn flag
Try removing step 3. Please edit your question with more details. Which server fails, A or B or both? Are they on the same or different sub-nets? Does "A" to/from "B" involve two different network interface cards on "A". Does ping with DNS lookup work? i.e. `ping 8.8.8.8`
Mateo Garcia avatar
fm flag
Thanks @DougSmythies for your answer, I'll edit my question. I test it without step 3 and it doesn't work. Server A fails and after step 4 I can't ping anything. The servers aren't in a same location and aren't on the same sub-nets. ping 8.8.8.8 works fine.
vidarlo avatar
om flag
What are you trying to achieve? *Connecting servers together* is kinda vague.
Mateo Garcia avatar
fm flag
Certain websites are blocked here (By the Government) such as YouTube, Coursera and etc. I'm trying to use this as a VPN. I have CISCO on the second server, My problem is about forwarding the traffic from the first one to the other one.
vidarlo avatar
om flag
Set up a tunnel using e.g. ssh, OpenVPN, Wireguard or whatever. Or tell ssh to use A as a jumphost to reach B.https://www.tecmint.com/access-linux-server-using-a-jump-host/ for instance...
Mateo Garcia avatar
fm flag
Thanks @vidarlo, I used this commands on my previous VPS provider (For Server A) and it was fine, the problem occurred when I changed my VPS provider.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.