LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-23-2014, 12:33 PM   #1
kijamun
LQ Newbie
 
Registered: Oct 2014
Posts: 1

Rep: Reputation: Disabled
Iptables: forward port from one host to another inside same bridged network


I have a network like this:

Code:
Internet <===> Modem/Router <--------->  Switch
           1.2.3.4    192.168.1.1/24     |  |  |
                                         |  |  |
                                   +-----+  |  +------+
                                   |        |         |
                                  PC_2      |        PC_3
                          192.168.1.3/24    |       192.168.1.4/24
                                            |
                                           PC_1
                                       192.168.1.2/24
                                           /|\
                                           WLAN
                                          / | \
                                    PC_W1 PC_W2 PC_W3 
                                     192.168.1.X/24 (X>10)
Modem/Router act as DHCP server too. Any request sent on public IP 1.2.3.4 is redirected to 192.168.1.2 on internal network. Modem/Router belong to ISP and I can't access/configure it. PC 1 is a linux box: eth0 and wlan0 are bridged (enslaved to br0 with address 192.168.1.2); hostapd is running on PC 1 sharing internet connection with PC WX. I want to redirect connections to some ports on PC 1 toward PCs on the same net, eg:

1.2.3.4:2222 > 192.168.1.2:2222 -> 192.168.1.3:22
1.2.3.4:3333 > 192.168.1.2:3333 -> 192.168.1.4:25

I tried using iptables and enabling ip_forward

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -d 192.168.1.2 -p tcp --dport 2222 -j DNAT --to 192.168.1.3:22
iptables -t nat -A POSTROUTING -d 192.168.1.3 -p tcp --dport 22 -j SNAT --to-source 192.168.1.2

and so on for others ports, but it didn't work. I discovered that redirections toward any other PC connected via WLAN works fine. It seems that, using iptables PREROUTING rule in conjunction with a bridge, once a packet has entered the bridge from one side (eth0), it can only flow to the other side (wlan0), but can't go out throw the same input interface. The arrangement described above works fine when the bridge is disabled, but I dont't want to use PC 1 as a router but as AP only.

Can someone help me?

Last edited by kijamun; 10-24-2014 at 03:30 AM.
 
Old 10-24-2014, 08:56 PM   #2
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
If the PC is bridging the traffic, leave it out of the equation completely. Just redirect the ports to the PCs you want to service the connection.

If you've tried this and it isn't working, check the setup of the bridging PC - it's possibly filtering traffic unexpectedly.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
To log in a guest (bridged), do I need to open the port on the host? yzT! Linux - Networking 4 04-08-2014 04:58 AM
iptables forward port to another host sparkey Linux - Networking 7 04-17-2013 08:49 PM
How do I forward connections to a computer on a bridged network connection? Kvbx4 Linux - Newbie 8 07-29-2012 11:21 PM
Forward port 80 for all traffic except to certain host/network fantasygoat Linux - Networking 3 12-04-2009 12:08 PM
iptables inside client to inside host with outside DNS or IP - Help! linuxhelp2 Linux - Networking 1 10-15-2005 06:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration