You are not logged in.

#1 2010-06-26 09:40:05

Revelation60
Member
From: The Netherlands
Registered: 2009-03-19
Posts: 158
Website

iptables: rerouting calls to external IP directly to local IP address

I am writing a multiplayer game, and for testing I am running the server and client on the same computer. The server connects to a master server, so the client receives the WAN IP of the local server. My router however, does not allow communication from the inside to the inside using the external IP. This has nothing to do with port forwarding (I should note that only the ISP has admin rights of the router). When my partner tries to login from an external pc, everything is fine.

Then the idea came to mind to reroute traffic to my external IP directly to my local IP. This is my iptables config file:

*nat
PREROUTING ACCEPT [0:0]
OUTPUT ACCEPT [528:31680]
POSTROUTING ACCEPT [528:31680] PREROUTING -d 87.209.57.151 -j DNAT --to-destination 192.168.1.3
COMMIT

87.209.57.151 is my WAN IP and 192.168.1.3 is my local address. This is not working however. What am I doing wrong?

Offline

#2 2010-06-26 14:35:16

Sin.citadel
Member
Registered: 2008-01-22
Posts: 267

Re: iptables: rerouting calls to external IP directly to local IP address

so, your local server first connects to a master server and transfer info/etc. your client connects to the local server only for communication, or that the local server tells the client after connection to use a specific WAN server for communication?

Offline

#3 2010-06-26 14:44:33

Revelation60
Member
From: The Netherlands
Registered: 2009-03-19
Posts: 158
Website

Re: iptables: rerouting calls to external IP directly to local IP address

The local servers registers itself with a master server. The client connects to the master server to get a list of servers. Then if you select a server, you connect to it. If you happen to connect to a server that is on your LAN, you are connecting to a local server through the external IP, because that one gets registered on the master server.

Offline

#4 2010-06-26 20:38:08

Sin.citadel
Member
Registered: 2008-01-22
Posts: 267

Re: iptables: rerouting calls to external IP directly to local IP address

if your local server has an interface with a WAN IP assigned to it, and the clients inside the NAT ask for services for your WAN IP, your local server (at least linux) doesnt try to NAT the connection and then forward it to internet, it directly connects you with your local server.

if you have access to directly attach a WAN IP, you should try using that, otherwise you can configure your router to forward all inbound traffic to your machine (DMZ)

Offline

#5 2010-06-27 09:57:09

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: iptables: rerouting calls to external IP directly to local IP address

That should work, but don't forget you'll need a rule in the FILTER table to allow the traffic back (bounce routing)

Assuming your LAN is eth1:

-i eth1 -o eth1 -j ACCEPT

Of course, if this is on your local machine (not a separate firewall/gateway) then it would actually need to be loopback interface:

-i lo -o lo -j ACCEPT

Offline

#6 2010-06-27 10:04:07

Revelation60
Member
From: The Netherlands
Registered: 2009-03-19
Posts: 158
Website

Re: iptables: rerouting calls to external IP directly to local IP address

I am really a beginner with iptables. Could you please give the whole command? The server is running on my local machine, btw. Thanks!

edit:

is this what you mean?

 *filter
 :INPUT ACCEPT [1579:938624]
 :FORWARD ACCEPT [0:0]
 :OUTPUT ACCEPT [1681:275967]
 -A FORWARD -i lo -o lo -j ACCEPT 
 COMMIT

If so, it isn' t working yet sad

Last edited by Revelation60 (2010-06-27 11:30:25)

Offline

#7 2010-06-27 23:12:03

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: iptables: rerouting calls to external IP directly to local IP address

What is the output of:

iptables -nvL
iptables -t nat -nvL

Offline

#8 2010-07-02 12:48:11

Revelation60
Member
From: The Netherlands
Registered: 2009-03-19
Posts: 158
Website

Re: iptables: rerouting calls to external IP directly to local IP address

Sorry for the late reaction. I only have this computer available in the weekends.

Output of iptables -nvL:

Chain INPUT (policy ACCEPT 29385 packets, 39M bytes)
 pkts bytes target     prot opt in     out     source               destination         
 837K   86M ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           

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

Chain OUTPUT (policy ACCEPT 19236 packets, 1985K bytes)
 pkts bytes target     prot opt in     out     source               destination         
 837K   86M ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0

And of iptables -t nat -nvL:

Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DNAT       udp  --  *      *       0.0.0.0/0            87.209.57.151       udp dpt:1234 to:192.168.1.3 

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

Chain POSTROUTING (policy ACCEPT 81192 packets, 4874K bytes)
 pkts bytes target     prot opt in     out     source               destination

I tried 192.168.1.3 instead of 127.0.0.1.

Offline

#9 2010-07-03 02:52:53

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: iptables: rerouting calls to external IP directly to local IP address

Okay I'm going to repeat what I think your trying to do....

So in that picture describes how the physical and network is setup.
You have Port forwarding set- up to

Client + Server
  192.168.1.3
       |
       |
       |
  Router-NAT      -------- The Game Ports are forwarded to IP 192.168.1.3
87.209.57.151
       |
       |
       |
  Master Server
  123.45.67.89


- You want to do is run a Game Server on your computer.
- You want your friends to be able to connect to it and play.
- You also want to connect to it and play.

- WORKING -
- Your Friends are able to connect to your Game Server and play. SO. . .
= Server IS working
= Ports are Forwarded

- NOT WORKING -
- You can not connect to your Game Server from the client running on the same box by using the Public IP address.

########################################

What Game is it ?
Dose the Game Client have a Network option to "Connect to local Server" or LAN Server ?

If your friends CAN connect and play then you should NOT bother with the Master Game Server. Just chose to connect to a Local Server and then type in the loop back address 127.0.0.1 or 192.168.1.3

You should not need to setup any routing rules on your Client/Server computer. Just port forwarding on the router.

..Edited out gibberish.

Last edited by hunterthomson (2010-07-03 04:08:51)


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

#10 2010-07-03 03:20:58

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: iptables: rerouting calls to external IP directly to local IP address

hunterthomson wrote:

Owe,... Also do you have the loop back module in your rc.conf file....

MODULES=(loop .........)

No no no no!! The kernel 'loop' module has nothing to do with networking! wink

Move your DNAT rule from PREROUTING to OUTPUT in the nat table... Because all the traffic is local (ie, not a firewall separate to your computer) the traffic doesn't get passed through PREROUTING, only OUTPUT.

Offline

#11 2010-07-03 04:07:02

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: iptables: rerouting calls to external IP directly to local IP address

Owe okay, that make sens now that I think about it.


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

#12 2010-07-03 08:41:39

Revelation60
Member
From: The Netherlands
Registered: 2009-03-19
Posts: 158
Website

Re: iptables: rerouting calls to external IP directly to local IP address

It is working now! The OUTPUT line did the trick smile

What Game is it ?
Dose the Game Client have a Network option to "Connect to local Server" or LAN Server ?

It is an open-source game called WalledIn I am writing with a friend. It does not have a LAN feature yet.

Offline

Board footer

Powered by FluxBB