How can route traffic from one machine to another machine
I have two Linux servers, one(Linux Server = S1) is used in LAN and another(Linux Server 2 = S2) is not in LAN and has a valid IP address.
I want to route all traffic from PCs to S2. So at first, i set S1 as all PCs' gateway. Now i want to route all traffic from S1 to S2, but i could not. Can Linux iptables do it? If yes, How? If no, How can i route all traffic from S1 to S2? I uploaded an image to show my intention in http://s17.postimage.org/i0qxi8bn3/filter.png |
Google: Linux as router
Ip4 forwarding and iptables nat should do the trick. |
NAT is not solution
Based on this topology NAT is not a solution because I want to direct all traffic from S1 to S2, not NAT. I will use NAT in S2 for internet connection.
How can I direct all traffic from S1 to S2? |
What are the default gateway address of the hosts?
Is the S1 <-> S2 connection on a different subnet from the LAN? As mentioned by battler, enabling ip_forwarding will allow you to route traffic between subnets. You want the two interfaces for S1 to be on different subnets to allow the routing rules to route between the interfaces. The other hosts need to know to use S1 as the default gateway. |
I'll try to explain it better:
On S1 you configure: DHCP: /etc/dhcp/dhcpd.config Quote:
/etc/sysctl.conf: Quote:
ETH0 (link to S2) /etc/network/interfaces Quote:
ETH1 (link to lan) /etc/network/interfaces Quote:
On S2 you configure ETH0 (link to WAN) /etc/network/interfaces Quote:
/etc/network/interfaces Quote:
Quote:
|
S1 & S2 is not in a subnet.
battler, thanks a lot. But I said S1 & S2 is not in a subnet and there are routers and switches between S1 and S2.
How can I direct all traffic from S1 to S2, and from S2 to S1? |
I'm sorry I didnt got that. You have two options.
1: Choose a routing protocol (RIP or OSPF). You can use this if the routers and switches between S1 and S2 are under your control. The advantage of using a dynamic routing protocol is the the automatic rerouting when lines in the network go down. 2: Remote Site VPN (OpenVPN). You can use this if you want to route traffic across networks that are not under your control (like the internet). You can encrypt your data to make sure it's safe to route your traffic across someone else's network. |
All times are GMT -5. The time now is 07:50 AM. |