Simple port fwd. 1 interface


 
Thread Tools Search this Thread
Special Forums IP Networking Simple port fwd. 1 interface
# 1  
Old 11-28-2012
Simple port fwd. 1 interface

I have been tearing my hair out with this (and not enough left to keep going).
I have a linux box (raspberry pi) single ethernet interface in a heavily filtered DMZ with external ports fwd'd that can access an internal IP's (different subnet).
I want to forward the traffic. Should be simple I thought and in fact I have it working using 'nc' as a 'one hit' as follows

Code:
mkfifo backpipe
nc -l 80  0<backpipe | nc 172.16.100.102 80 1>backpipe

But I need this to be a permanent fwd. So after much googling tried to set up iptables to do this.

IP of pi is 192.168.1.8 it has an external IP with management port and port 80 fwd's at the router to the internal ip. The IP of the service I am trying to fwd to is 172.16.100.102 which is accessible as I said above from the PI (but not explicitly in the pi's routing table, just accessible via the default route)

I have enabled fwd'ing on the eth0 interface
Code:
"echo '1' > /proc/sys/net/ipv4/conf/eth0/forwarding"

I have tried several slightly different rulesets but feel the following is the closest

Code:
iptables -t nat -A PREROUTING --dst 192.168.1.8 -p tcp --dport 80 -j DNAT --to-destination 172.16.100.102:80
iptables -t nat -A POSTROUTING -p tcp --dst 172.16.100.102 --dport 80 -j SNAT --to-source 192.168.1.8
iptables -t nat -A OUTPUT --dst 192.168.1.8 -p tcp --dport 80 -j DNAT --to-destination 172.16.100.102:80

this gives me the following info
Code:
root@raspberrypi:/home/pi# iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 1 packets, 78 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DNAT       tcp  --  *      *       0.0.0.0/0            192.168.1.8          tcp dpt:80 to:172.16.100.102:80

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

Chain OUTPUT (policy ACCEPT 2 packets, 152 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DNAT       tcp  --  *      *       0.0.0.0/0            192.168.1.8          tcp dpt:80 to:172.16.100.102:80

Chain POSTROUTING (policy ACCEPT 2 packets, 152 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 SNAT       tcp  --  *      *       0.0.0.0/0            172.16.100.102       tcp dpt:80 to:192.168.1.8

I know it's working to an extent (that is doing something to port 80) as if I have the port open and logging ( nc -l localhost 80 > log.txt ) and then implement the iptables rules above I can no longer connect to port 80 until I purge the rules again.

I also notice that iptables doesn't seem to actually 'open' the port.
So questions are twofold.
1) do I have to activate a service to open the port so that the iptables rules can then apply or is there a way to have iptables open the port?
2) how do I make this damn thing work? Smilie

Any input greatly appreciated.

---------- Post updated at 11:49 AM ---------- Previous update was at 05:29 AM ----------

Could a moderator please move this to the IP Networking Thread ? as I think it would be more relevant there.

---------- Post updated 11-28-12 at 09:25 AM ---------- Previous update was 11-27-12 at 11:49 AM ----------

Managed to get this working much more simply as follows:
Code:
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp -s 0/0 -d 192.168.1.8 --dport 80 -j DNAT --to 172.16.100.102:80
iptables -t nat -A POSTROUTING -o eth0 -d 172.16.100.102 -j SNAT --to-source 192.168.1.8


Last edited by Scott; 11-27-2012 at 06:38 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Port based multi interface routing

Hello, I wanted to setup routing certain traffic (http/s) out via a second (faster) interface, like described in the following docs (may not post urls): linux-ip.net /html/adv-multi-internet.html thegeekstuff.com /2014/08/add-route-ip-command/ I already had this working years ago on... (0 Replies)
Discussion started by: hyphan
0 Replies

2. Solaris

How to find port number wwn of particular port on dual port HBA,?

please find the below o/p for your reference bash-3.00# fcinfo hba-port HBA Port WWN: 21000024ff295a34 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3356-02 Firmware Version: 05.03.02 FCode/BIOS Version: BIOS: 2.02; fcode: 2.01;... (3 Replies)
Discussion started by: sb200
3 Replies

3. Shell Programming and Scripting

Grep regex to ignore sequence only if surrounded by fwd-slashes

Hi, I've got a regex match to perform in a Bash script and can't quite get it right. Basically I want to match all IP address like sequences in a file which may or may not contain an IP address but with the extra qualification of ignoring any IP-like sequence which begins and ends with a... (27 Replies)
Discussion started by: gencon
27 Replies

4. Red Hat

Find out which eth or device belongs to interface "port 1 PCI 4"

Hi, I´ve given only this info to configure a network interface : "port 1 PCI 4" I´ve been searching for any kind of relationship in the system which allow me to find the etc that must be configured... Please, could anybody help me? rhxx:#/root# lspci |grep -i "PCI BRIDGE" 00:01.0 PCI... (0 Replies)
Discussion started by: pabloli150
0 Replies

5. Red Hat

iptable port forwarding between two lan interface

Hi, How can I config iptables to allow port forwarding from one WAN interface to second lan interface . In my system I have one wan interface 61.93.204.56 (eth0),and lan interface 10.2.1.52(eth1) I want to make port forward port no 22 from 61.93.204.56 to port 22 , 10.2.1.52 , tcp and udp... (1 Reply)
Discussion started by: chuikingman
1 Replies

6. Web Development

Need to run Nagios Web Interface on a different port

Hi, During Nagios install we added the following piece of config to apache httpd.conf file and it runs on the regular port 80, now if I want to run this on a different port then what needs to changed to make it run on lets say port 8080. I tried adding Virtual servers but was getting... (1 Reply)
Discussion started by: jacki
1 Replies

7. SCO

Change SCO - GUI or Desktop interface to DOS based interface

Hi all I have installed a demo version of SCO OpenServer 5.0.2, I finally found it is Desktop Interface, I would like to know how to change its interface to dos based interface? If you have any ideas, please tell me then. Thank you (2 Replies)
Discussion started by: TinhNhi
2 Replies

8. Red Hat

Assign port dedicatedly against an interface !

Dear Friends , I am using RHEL 5 . In my Linux Box i have two Lan cards (eth0 and eth1) . "eth0" is connected with network 192.168.10.0 and "eth1" is connected with network 192.168.11.0 . Both Network are inter connected via routing . Now I want a situation where , I want to dedicatedly... (2 Replies)
Discussion started by: shipon_97
2 Replies

9. Fedora

Hosting issue regarding subdirectories and fwd Slashes

I admin two co-located servers. I built an app that creates subdirectories for users ie www.site.com/username. one server that works just fine when you hit that url, it sees the index within and does as it should. I moved the app to my other server running FEDORA 1 i686 standard, cPanel... (3 Replies)
Discussion started by: iecowboy
3 Replies

10. Solaris

Simple port fowarding help

Hello all am new to unix i have acces to unix machine s commandline at my collage wen entering uname -a command i get this output SunOS ws7 5.8 Generic_108528-20 sun4u sparc SUNW,Sun-Blade-1500 all i need help in seting up a simple prort forward from this machine ie this machine listen on... (5 Replies)
Discussion started by: nizammoidu
5 Replies
Login or Register to Ask a Question