Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Because my wireless router's ethernet ports are defective, I set up a shared wireless connection from my laptop (which has wifi) to my eMac (which does not) via a crossover ethernet cable. The laptop is behind a router as 192.168.1.131, and the eMac is behind the laptop as 10.42.43.1 .

The laptop is running Ubuntu 9.10 (Karmic). I achieved the shared connection through NetworkManager Applet. I right-clicked on the network icon at the topright, went to Edit Connections, selected the Wired connection named "Auto eth0", clicked "Edit...", went to the "IPv4 Settings" tab, and selected the Method "Shared to other computers". The eMac can now access the Internet.

Now I want to enable port forwarding. There's a game I want to play that needs port 6112 forwarded (both TCP and UDP) in order to host games. I set up the router to enable port forwarding for 192.168.1.131 (the laptop), but port forwarding still isn't available on the eMac.

I suppose I need to pretend my laptop is a router and configure port forwarding on it, indicating that incoming connections to the laptop (192.168.1.131) should be forwarded to the eMac on the shared connection (10.42.43.1 ). Thus, packets coming into the router on port 6112 would be redirected to the laptop (by the router), then to the eMac (by the laptop).

My question is, how would I do that on Ubuntu (in light of NetworkManager's presence)? Also, if I can't get this to work, does anyone mind hosting a comp stomp? :D

share|improve this question
add comment

2 Answers

Don't know anything about Ubuntu config utils but here's the classic way:

echo 1 > /proc/sys/net/ipv4/ip_forward # enable forwarding
iptables -I FORWARD -p tcp -d 192.168.1.131 --dport 6112 -j ACCEPT #just to be sure firewall doesn't block
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 6112 -j DNAT --to 10.42.43.1 #actual forward
#same for UDP
iptables -I FORWARD -p udp -d 192.168.1.131 --dport 6112 -j ACCEPT
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 6112 -j DNAT --to 10.42.43.1 

You have to change -i eth0 to your wlan connection name. Generally

iptables -t nat -A PREROUTING [-p protocol] --dport [external port on router] -i ${WAN} -j DNAT --to [ip/port to forward to]

For more check Frozentux iptables guide.

share|improve this answer
add comment

Consider installing the Shorewall package to configure your routing. Your forwarding rules would be done using DNAT rules. I would suggesst starting with the example 2 interface configuration.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.