LinuxQuestions.org
Review your favorite Linux distribution.
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 04-04-2020, 12:09 PM   #1
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Rep: Reputation: Disabled
Forwarding traffic to Internet GW


I have a server at 192.168.2.1, and my main server (GW to internet) internal IP at 192.168.1.1. In between is my laptop where I interact with both networks.
I did the following on 2.1:
Code:
route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.2
route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.2   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
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
Where my laptop is 192.168.1.2.
Here is what my laptop's routing table looks like:
Code:
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
I would like to be able to get out to the internet from the 2.1 network.
 
Old 04-04-2020, 02:28 PM   #2
kermitdafrog8
Member
 
Registered: Dec 2018
Location: Orlando, FL
Distribution: Slackware AARCH64 and X86_64
Posts: 340

Rep: Reputation: Disabled
Forwarding traffic to Internet GW

You want your laptop on 2.x network to connect to you gw through the linux server?
 
Old 04-04-2020, 03:43 PM   #3
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Original Poster
Rep: Reputation: Disabled
So it does have a 2.x IP. But devices on the 2.x network can't communicate out to the linux server.
 
Old 04-04-2020, 04:47 PM   #4
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,857

Rep: Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150
You should be able to do this on the fly using...
Code:
route del default gw 192.168.1.1
Code:
route add default gw 192.168.2.1
 
Old 04-18-2020, 11:17 AM   #5
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Code:
 route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.2
route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.2   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
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
This would confuse any machine with 2 default routes to the world on the same interface and 2 different gateways.
If I am understanding correctly you want the server at 2.1 to be able to reach the outside (or at least 1.1) by routing through the laptop.

The laptop would need 2 physical interfaces, or 2 virtual interfaces configured on 1 physical interface.

something like this
ISP gateway----------laptop----------server
---1.1-----------------1.2 & 2.2---------2.1

The laptop would need to have 2 interfaces (hardware or virtual) one on each network (1.0 and 2.0) with the appropriate IP assigned to each.
the server would then need the default route to point to 2.2 and the laptop would point to 1.1
while the routing on gateway machine would need a dedicated route for the 2.0 network pointing to 1.2 and the laptop would also need routing for the 2.0 network going out the appropriate interface.

The virtual interfaces on the laptop for eth0 could then be the 1.2 and eth0:0 could then be 2.2 with the routing tables accordingly.

Your original post shows 2 interfaces (eth0 and eth1) on the laptop but you do not show an IP assigned to eth1.

Update:
An alternative to changing the routing on the 1.1 server would be to use dnsmasq on the laptop and the 1.1 server would then see everything from the 2.1 server as if it originated from the laptop so no extra routing would be needed there

Last edited by computersavvy; 04-18-2020 at 02:08 PM. Reason: update
 
  


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
[SOLVED] forwarding all internet traffic through proxy BHABANIPRASADPATI Linux - Networking 2 07-20-2011 10:20 AM
Mail Forwarding in postfix/maildrop/redhat (like yahoo mail forwarding) topcat Linux - Software 1 08-31-2007 12:10 PM
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
Simple Port Forwarding Firewall - not forwarding MadTurki Linux - Security 14 04-09-2006 12:08 PM
port forwarding and packet forwarding syrtsardo Linux - Newbie 2 07-03-2003 10:37 AM

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

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