[SOLVED] Port Forwarding inside LAN not connected to a router nor internet
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Port Forwarding inside LAN not connected to a router nor internet
I have read a lot of tutorials and examples for setting up port forwarding. Most of them describe a setup with computers connected to a router that is connected to the internet. My setup is much simpler. I have a Windows PC, a linux machine, and an embedded device. I am trying to use the linux machine as a router between the Windows PC and the embedded device:
I setup eth0 and eth1 to be on different networks because they are physically located on the same linux machine. And I've set:
echo 1 > /proc/sys/net/ipv4/ip_forward
I've located the /etc/sysconfig/iptables config file, and I've tried setting up port forwarding according to the many different tutorials I've found online. None of them seem to work! I need at least FTP and SNMP to work, and it would be nice if I could ping the embedded system as well. I know there are much easier ways to setup communication between the PC and the embedded system than using port forwarding. Why I'm doing it this way would take awhile to explain! Simply using gateway addresses will cause network conflicts for the bigger design.
If someone could help me setup my iptables config file, I think that should be enough for me to get started. I've been at this for about a week, and I still don't really understand the iptables options.
I'm attempting to use NAT to make the Embedded System server 192.168.240.10 on the 192.168.240.xxx network appear as IP address 192.168.220.100 on the 192.168.220.xxx network. All communication to the embedded system 192.168.240.10 will be done using this new IP address 192.168.220.100.
As I said before, by first, PC must to known where it should send packets, so it must be configured.
Please post output of "route -n" on that PC. If you want all communication from PC go through Debian router its default route must be configured as
Code:
0.0.0.0 192.168.220.2 0.0.0.0 UG 100 0 0 eth0
I suppose its eth0 interface is connected to Debian router eth0. Please clarify if this PC has more intefaces or should not transfer whole communication by Debian router.
'route -n' does not seem to work... but I think that 'route print' is the output that you were looking for? the interface that I have connected to linux 'eth0' is 'Ethernet adapter Local Area Connection 2'
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Louis>
C:\Documents and Settings\Louis>ipconfig
So, as you see, when PC want to send packets to 192.168.220.100 it sends it to 192.168.220.1 (self) but should to 192.168.220.2 (your Debian router). It doesn't even known of existing your router in the network.
Sorry, but I don't known how to configure routes on Windows. Search Internet for this or maybe other guys from LQ can help you. Also it has other interfaces, so you probably do not want transfer all communication by your Debian router, but only for host 192.168.220.100. You can also start a DHCP service on the router (for example dnsmasq), so Windows using it automaticaly configure own routes.
P.S. Please use a CODE tags around your copy/paste text, as without it, it is difficult to read.
Why not just turn on routing on the Linux computer and directly access the IP of the embeeded device from the windows computer using linux as the router?
On the linux box set:
"FORWARD_IPV4=true" in /etc/sysconfig/network
on the windows box:
route add 192.168.240.0 mask 255.255.255.0 192.168.220.2 metric 2
Use the above for testing if it works add -p to make it persistent on windows.
The reason that your SNAT rule is requiered is because the "embeded device" does not know where to send return traffic that originated on the 192.168.220.0/24 network. If you set the default gateway on the embeded device to 192.168.240.1 then will be able to drop that rule from IP tables.
Once you have set the default gateway, this script should work, even if your IP address on the eth0 network changes.
With that said, I would suggest that you isolate exaclty which traffic you need to deliver to the embeded device and create specific rules for it. Otherwise you will not be able to access the Linux box from the external network.
Unfortunately I can't access the network configuration on the embedded device. The IP address and the subnet mask and the default gateway are hardcoded!
The routed solution I suggested should fix this problem if you you have the IP of the linux box on the interface connected to the embedded box set as the hard coded gateway.
IP on Linux box eth1 = hardcoded gateway from embeded device.
Don't forget to set FORWARD_IPV4=true as mentioned in my previous post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.