LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 05-07-2012, 06:25 AM   #1
pronetin
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Rep: Reputation: 0
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
 
Old 05-07-2012, 06:40 AM   #2
battler
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Rep: Reputation: Disabled
Google: Linux as router
Ip4 forwarding
and iptables nat should do the trick.
 
Old 05-12-2012, 10:58 PM   #3
pronetin
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Unhappy 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?
 
Old 05-13-2012, 12:35 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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.

Last edited by jschiwal; 05-13-2012 at 01:56 AM.
 
Old 05-13-2012, 05:26 AM   #5
battler
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Rep: Reputation: Disabled
I'll try to explain it better:

On S1 you configure:

DHCP:
/etc/dhcp/dhcpd.config

Quote:
# A slightly different configuration for an internal subnet.
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option domain-name-servers [dns server]
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;
}
IPv4 Forwarding
/etc/sysctl.conf:
Quote:
net.ipv4.ip_forward = 1

ETH0 (link to S2)

/etc/network/interfaces
Quote:
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255

ETH1 (link to lan)

/etc/network/interfaces
Quote:
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

On S2 you configure


ETH0 (link to WAN)

/etc/network/interfaces
Quote:
iface eth0 inet dhcp
ETH1 (link to S1)
/etc/network/interfaces
Quote:
iface LAN inet static
address 192.168.2.2
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
NAT
Quote:
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT

Last edited by battler; 05-13-2012 at 05:29 AM.
 
Old 05-13-2012, 11:16 PM   #6
pronetin
LQ Newbie
 
Registered: Dec 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Unhappy 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?

Last edited by pronetin; 05-13-2012 at 11:17 PM.
 
Old 05-16-2012, 10:44 AM   #7
battler
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
  


Reply

Tags
linux, network, route, routing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to route 2 interface one with local GW and one with VPN on the same machine. Tampen Linux - Networking 4 04-25-2012 10:18 PM
how to know the remote machine is Virtual machine or physical machine pantdk Linux - Server 15 11-20-2011 06:46 PM
How to route traffic on a network - cannot get machine to transfer across interfaces captainpotato Linux - Networking 15 10-04-2006 08:04 AM
Need Linux machine to route / packet forward rdd Linux - Networking 3 06-24-2004 09:59 AM
Wireless traffic stomps isdn traffic on gateway machine Radix999 Linux - Wireless Networking 0 11-14-2003 12:54 AM


All times are GMT -5. The time now is 04:24 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration