LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-24-2011, 07:33 PM   #1
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Rep: Reputation: 0
Question Routing or Bridging


Objective
-------------
I am trying to connect a desktop(in LAN) to internet by setting its gateway on another desktop who is on a different LAN and getting internet by having its gateway configured on a DHCP server.

Scenario
---------
System A (Virtual Machine)
NIC - eth0
IP 192.168.1.2
Netmask 255.255.255.0
Gateway 192.168.1.1
Broadcast 192.168.1.255
OS Ubuntu

System B (Server, Virtual Machine)
NIC - eth0 and eth1
eth0-IP 10.1.31.5 (through DHCP, internet enabled)
Netmask 255.255.0.0
Gateway 10.1.31.254 (configured on another DHCP server)
OS Ubuntu

Configuration
---------------
I have configured the eth1 of System B as a gateway of system A with IP 192.168.1.1, netmask 255.255.255.0.
System B is able to ping System A and vice-versa but no internet on system A.

What I want to do is to get the internet on system A from system B.

What I am confused about is what I require?
- do I need to bridge eth0 and eth1 on System B and then routing packets from System A via its gateway configured on system B?
- do I need to add routing rules on system A and B that will do the following-
1. when I will type ping www.google.com on system A, the packet will reach on eth1 of systemB.
2. eth1 of systemB will pass the packet to eth0 of systemB and it will be passed to the gateway of systemB which is configured on a DHCP server and hence connecting to the internet.

I dont know if the logic seems to be fully correct or not but I need your help guys.
I tried doing both the things but something is not working the way it should be. I need someone who can guide me to this to get it working.

Please help.
 
Old 03-25-2011, 12:30 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Q: Did you turn on ip forwarding on System B?

Last edited by paulsm4; 03-25-2011 at 12:31 AM.
 
Old 03-25-2011, 12:52 AM   #3
tommylovell
Member
 
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380

Rep: Reputation: 103Reputation: 103
Quote:
- do I need to bridge eth0 and eth1 on System B and then routing packets from System A via its gateway configured on system B?
I don't think you want to bridge.

You essentially have this.
Code:
[Internet]<--->[router]10.1.31.254<--->10.1.31.5[System B]192.168.1.1<--->192.168.1.2[System A]
Probably the easiest way to accomplish what you want is to set up Network Address Translation on System B.
(System A remains unchanged.) I think IPTABLES is capable of doing this.

This will turn on ip forwarding temporarily.
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
This will turn it on permanently.
Code:
echo "# Controls IP packet forwarding
net.ipv4.ip_forward = 1" >> /etc/sysctl.conf 

sysctl -p
Then you'll need to configure iptables to forward the packets from your internal network on eth1, to your external network on eth0. I'm no expert, but you could try.
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
There's more than one way to do it. Google'ing will show you a lot of differ ways if this doesn't work.

The other alternative is to turn on just IP Forwarding on System B - no NAT, but your router would need to be able to do NATing from two inside networks and also be able to take a hardcoded route for the 192.168.1.0 network. Essentially, packets hitting System B's eth1 interface would be forwarded on to the router (with destination IP address unchanged). Traffic returning from the Internet would need to be translated back to the correct inside network, and the System A traffic would need to be routed back via 10.1.31.5. I can configure a route on my Linksys WRT150N. I don't know if it would handle the NATing from two networks to the Internet. I think the first option is far more viable.

Last edited by tommylovell; 03-25-2011 at 12:55 AM.
 
Old 03-25-2011, 12:00 PM   #4
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
I think the first option is far more viable

I tried by doing what you suggested. Enabled the ip forwarding and then connfigured the iptables. But it says unknown host whenever I am trying to ping any website from system A.
 
Old 03-25-2011, 12:01 PM   #5
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Yes I do

Quote:
Originally Posted by paulsm4 View Post
Q: Did you turn on ip forwarding on System B?
Yes I have enabled the IP forwarding on system B
 
Old 03-25-2011, 12:07 PM   #6
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Thumbs up

Quote:
Originally Posted by rgupta52 View Post
I tried by doing what you suggested. Enabled the ip forwarding and then connfigured the iptables. But it says unknown host whenever I am trying to ping any website from system A.
I am sorry. It just skipped of my mind. I tried to ping the IP of the websites and its done. I have to look for the name resolution now.

Thank you so much.
 
Old 03-25-2011, 12:18 PM   #7
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rgupta52 View Post
I am sorry. It just skipped of my mind. I tried to ping the IP of the websites and its done. I have to look for the name resolution now.

Thank you so much.
But there is still a problem. I edited the nsswitch.conf file but seems no gain. Its still able to ping any hostname.

Kindly suggest.
 
Old 03-25-2011, 12:23 PM   #8
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rgupta52 View Post
But there is still a problem. I edited the nsswitch.conf file but seems no gain. Its still able to ping any hostname.

Kindly suggest.
Sorry to bother again. Its done and finalized now. What went wrong was somehow entries in the resolve.conf files were getting omitted. Its fixed now.

Thanks.
 
Old 03-25-2011, 12:29 PM   #9
tommylovell
Member
 
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380

Rep: Reputation: 103Reputation: 103
If system A is configured for a static IP address, then you won't be getting your nameservers from DHCP...

Look at /etc/resolv.conf. If there are no nameservers listed, 'cat /etc/resolv.conf' on System B and copy that DHCP supplied info to System A.

It should take a form something like this.
Code:
domain <yourdomain>
search <yourdomain>
nameserver aaa.bbb.ccc.ddd
nameserver eee.fff.ggg.hhh
'dig' and 'nslookup' are helpful for seeing what is happening with DNS lookups.

EDITED: oops, I guess timing is everything...

Last edited by tommylovell; 03-25-2011 at 12:30 PM. Reason: too slow with a reply.
 
Old 03-25-2011, 12:34 PM   #10
rgupta52
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by tommylovell View Post
If system A is configured for a static IP address, then you won't be getting your nameservers from DHCP...

Look at /etc/resolv.conf. If there are no nameservers listed, 'cat /etc/resolv.conf' on System B and copy that DHCP supplied info to System A.

It should take a form something like this.
Code:
domain <yourdomain>
search <yourdomain>
nameserver aaa.bbb.ccc.ddd
nameserver eee.fff.ggg.hhh
'dig' and 'nslookup' are helpful for seeing what is happening with DNS lookups.

EDITED: oops, I guess timing is everything...

Yeah I did the same as you mentioned and got it working. Thanks Boss !!!
 
  


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
Need some ideas for bridging or routing between 2 segments with 2 internet providers. Sm0k3 Linux - Networking 1 03-23-2010 08:33 PM
VMWare's bridging vs Window's bridging - routing is messed up when Windows bridging brenan99 General 0 05-04-2008 10:24 PM
[SOLVED] iptables 'bridging/routing' two interfaces for VPN PelliX Linux - Networking 10 10-27-2007 04:57 AM
Modems - bridging vs routing billymayday Linux - Hardware 2 07-26-2006 04:06 PM
bridging, routing and tunnels -- oh my! MatthewSabin Linux - Networking 1 08-27-2004 04:07 PM

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

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