Score:0

Port Forwarding in Ubuntu Server 22.04 not working for me

ua flag

I am fairly new to ubuntu and need help. I am running ubuntu server on my vps and home server. They are connected via Wireguard and I would like to forward the port 25565/tcp,udp to my home server. I tried many different versions of the prerouting command like Simple port forwarding and https://devstorage.eu/blog/linux-port-forwarding-mit-iptables/ but they only seem to work partly. I can connect to the minecraft server but time out on "Joining world". Pls help me and I am sorry if this is the wrong place to ask the question. I am quite sure that it is possible because I got it working on a Windows Laptop as home server and my vps but I forgot how I did it.

With these rules I encounter the "Joining World" problem:

Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination
DNAT       tcp  --  anywhere             ubuntu               tcp dpt:25565 to:10.7.0.2:25565
DNAT       udp  --  anywhere             ubuntu               udp dpt:25565 to:10.7.0.2:25565
DNAT       tcp  --  anywhere             anywhere             tcp dpt:25565 to:10.7.0.2:25565
DNAT       udp  --  anywhere             anywhere             udp dpt:25565 to:10.7.0.2:25565

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       all  --  10.7.0.0/24         !10.7.0.0/24          to:82.165.127.112
MASQUERADE  all  -- !localhost            anywhere
SNAT       tcp  --  anywhere             10.7.0.2             tcp dpt:25565 to:10.7.0.1
SNAT       udp  --  anywhere             10.7.0.2             udp dpt:25565 to:10.7.0.1

I tried:

iptables -t nat -A PREROUTING -j DNAT -d 10.7.0.1 -p udp --dport 25565 --to 10.7.0.2:25565 
iptables -t nat -A PREROUTING -j DNAT -d 10.7.0.1 -p tcp --dport 25565 --to 10.7.0.2:25565
sudo iptables -t nat -A PREROUTING -i ens6 -p tcp --dport 25565 -j DNAT --to-destination 192.168.178.57:25565
sudo iptables -t nat -A PREROUTING -i ens6 -p udp --dport 25565 -j DNAT --to-destination 192.168.178.57:25565 
and socat: socat TCP-LISTEN:25565,fork,reuseaddr TCP:10.7.0.2:25565

these command lead to the "Joining world" problem:

sudo iptables -t nat -A PREROUTING -i ens6 -p tcp --dport 25565 -j DNAT --to-destination 10.7.0.2:25565
sudo iptables -t nat -A PREROUTING -i ens6 -p udp --dport 25565 -j DNAT --to-destination 10.7.0.2:25565
iptables -t nat -A POSTROUTING ! -s 127.0.0.1 -j MASQUERADE

Homeserver 10.7.0.2/192.168.178.57 interface: enp12s0 VPS 10.7.01 interface ens6 + public ip: 82*

The ips 10.7.0.1/ .2 were assigned through wiregard and I thought you could use 10.7.0.2 and 192.168.178.57 interchangeably.

I want that when connecting to the vps public ip you would end up at 10.7.0.2 the homeserver.

sudo iptables -xvnL output:

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
  150991 18835792 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:51820

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
  273154 551566308 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
      53     3381 ACCEPT     all  --  *      *       10.7.0.0/24          0.0.0.0/0

sudo iptables -t nat -xvnL output:

Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
      40     2088 DNAT       tcp  --  ens6   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:25565 to:10.7.0.2:25565
       0        0 DNAT       udp  --  ens6   *       0.0.0.0/0            0.0.0.0/0            udp dpt:25565 to:10.7.0.2:25565

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
      37     2345 SNAT       all  --  *      *       10.7.0.0/24         !10.7.0.0/24          to:82.165.127.112
      57     7372 MASQUERADE  all  --  *      *      !127.0.0.1            0.0.0.0/0
       0        0 SNAT       tcp  --  *      ens6    0.0.0.0/0            10.7.0.2             tcp dpt:25565 to:10.7.0.1
       0        0 SNAT       udp  --  *      ens6    0.0.0.0/0            10.7.0.2             udp dpt:25565 to:10.7.0.1
Doug Smythies avatar
gn flag
Show us what you have done and what is working and not working. We need a lot more details.
mankenntihn25565 avatar
ua flag
I also enabled port forwarding in sysctl.
Organic Marble avatar
us flag
It's impossible to read long code segments in comments. Edit them into your question.
Doug Smythies avatar
gn flag
Which computer is which? what is 10.7.0.1? 10.7.0.2? You edited out 192.168.178.57, what is that? which interface is ens6? Describe packet flow, and support that information with `sudo iptables -xvnL` and `sudo iptables -t nat -xvnL` so packet counters can be observed.
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.