LinuxQuestions.org
Review your favorite Linux distribution.
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 12-18-2011, 03:36 PM   #1
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Rep: Reputation: 33
new to route command


Hi I'm trying to route a connection but it doesn't work. I don't really understand what goes wrong.

I've got a switch on 192.168.2.0. All my computers are on that network.

However there is one server that has 192.168.2.7 on eth0 and 192.168.1.1 on eth1. Through eth1 it connects with a crossover to 192.168.1.2 (that computer isn't connected to 192.168.2.0)

On one of my computers on 192.168.2.0 i entered the command:

Code:
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.2.7
I thought that would do the trick to connect straight away to my crossed over computer but it doesn't work yet. I think I need to put something in the routing table of 192.168.2.7 as well but what?
 
Old 12-18-2011, 03:39 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you need to configure the intermediary machine to forward packets.

test with:


echo 1 > /proc/sys/net/ipv4/ip_forward


and set permanently in /etc/sysctl.conf:


net.ipv4.ip_forward = 1
 
Old 12-18-2011, 03:51 PM   #3
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Original Poster
Rep: Reputation: 33
No that doesn't work. I tried to ssh directly and mount a drive on the computer behind the intermediate computer but that doesn't work.

Last edited by bucovaina78; 12-18-2011 at 03:54 PM.
 
Old 12-18-2011, 04:40 PM   #4
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Original Poster
Rep: Reputation: 33
I've done some more google-ing. I'm suspecting I need to configure iptables for NAT. But I've got no experience whatsoever with iptables. So I found this:

Code:
# /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# /sbin/iptables -A FORWARD -i eth0 -o eth1 -m state 
   --state RELATED,ESTABLISHED -j ACCEPT
# /sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
eth0 is my 192.168.2.0 network where all my computers are attached, eth1 is the cross over connection. is this right then?
 
Old 12-18-2011, 04:44 PM   #5
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
Quote:
Originally Posted by bucovaina78 View Post
No that doesn't work. I tried to ssh directly and mount a drive on the computer behind the intermediate computer but that doesn't work.
Two very critical core components need to be satisfied on the intermediary (gateway/router) system (192.168.2.7/eth0 192.168.1.1/eth1).

First, as acid_kewpie already indicated, IP-forwarding (routing) should be enabled.
Second, forwarding should be permitted via netfilter rules using iptables.
Code:
[root@192.168.2.7 ~]# iptables -I FORWARD -j ACCEPT
Without knowing what the routing system is we may guess and provide examples similar to our experiences, but they may not work exactly as demonstrated. Additionally, does the 192.168.1.2 system have a default route gateway of 192.168.1.1?
 
Old 12-18-2011, 04:50 PM   #6
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
Quote:
Originally Posted by bucovaina78 View Post
I've done some more google-ing. I'm suspecting I need to configure iptables for NAT. But I've got no experience whatsoever with iptables. So I found this:

eth0 is my 192.168.2.0 network where all my computers are attached, eth1 is the cross over connection. is this right then?
It depends. Do you want to actually route (each network knows about the other) or have 192.168.2.7 handle the address translation (192.168.1.2 does not know or care about 192.168.2.x -- similar to what most home router/firewall/access-points/modems do to connect systems to the Internet)?

With routing the intermediary system simply passes the packets, but with NATing/MASQUERADEing the intermediary system will actually take the packet and change the ip from 192.168.2.x to 192.168.1.1. Then 192.168.1.2 will reply to 192.168.1.1, upon receiving it 192.168.1.1/192.168.2.7 will identify that the packet is actually destined for 192.168.2.x, change the ip to that of 192.168.2.7 and kick it out on the wire to the intended IP on 192.168.2.x network.
 
Old 12-19-2011, 01:27 AM   #7
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Original Poster
Rep: Reputation: 33
I want to know all the hosts at 192.168.2.0 to know about the host(s) at 192.168.1.0 (I want to mount a CIFS)

I added the
Code:
IPTABLES -I FORWARD -j ACCEPT
and it doesn't work so far. I checked again the ip_forward variable in /proc/sys/net/ipv4 and it's still on 1. My routing table mentions 192.168.1.0 and 192.168.2.0 with the right devices.

Code:
root@intermediate:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere                      

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
root@intermediate:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.2.7     0.0.0.0         UG    0      0        0 eth0
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
root@intermediate:~# cat /proc/sys/net/ipv4/ip_forward 
1
root@intermediate:~#
 
Old 12-19-2011, 02:31 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
right, but the missing link is if then 1 subnet knows about the machines on 2. Either those machines need to know how to get back to that other network by having a route on them, OR you use a nat or masquerade on the router device so that all traffic from the 2 subnet appears to come from that router instead, which the 1 machines already know about.

Try to avoid using a nat if you can, you can possibly get away with adding a route onto default gateway device of the 1 machines, although this could result in unsuccessful attempts at asymmetric routing.
 
Old 12-19-2011, 04:15 AM   #9
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Original Poster
Rep: Reputation: 33
yes!! It's working now!! Thanks a lot acid_kewpie & rayfordj
 
Old 12-19-2011, 04:48 AM   #10
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Original Poster
Rep: Reputation: 33
Just to be complete:

I tried to mount the drive on 192.168.1.2 (remote computer) and I got an error connection refused (-111). So I added a line in /etc/hosts.allow:

Code:
192.168.2.0/24
Now the problem is solved.

Thanks to you all!
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Route command saran_redhat Linux - Newbie 1 01-24-2011 03:08 AM
Default route took 20s to display with 'route' command Akhran Linux - Newbie 3 11-04-2006 04:59 AM
I am not able to add a new route to my route table using route command prashanth s j Linux - Networking 2 09-03-2005 04:34 AM
Need help with route command dalek Linux - Networking 5 07-15-2005 12:26 AM
route command Mux Linux - Networking 9 05-10-2002 02:17 AM

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

All times are GMT -5. The time now is 05:40 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