LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-18-2014, 01:09 PM   #1
Seemoi
LQ Newbie
 
Registered: Feb 2009
Posts: 29

Rep: Reputation: 1
Force traffic to different subnet on same eth0 - iptables 10.0.0.4 to 10.29.70.4


Hello.

I'm connected via ssh : 10.0.0.4

I need to run $ sudo apt-get update on 10.0.0.4,
have the traffic redirected to to 10.29.70.4

Can I do this as root via iptables while on 10.0.0.4 ?

Thank you.
 
Old 04-19-2014, 08:01 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,149

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
I'm easily confused, so pardon the stupid question. Are 10.0.0.4 and 10.29.70.4 two different ports on the same machine? Obviously, only the machine running apt-get will understand the traffic resulting from the command.
 
Old 04-19-2014, 01:46 PM   #3
Seemoi
LQ Newbie
 
Registered: Feb 2009
Posts: 29

Original Poster
Rep: Reputation: 1
Sorry, I'll be more detailed...

Machine 1 (Client)= 10.0.0.2 # Client

Machine 2 (Ssh Server) = 10.0.0.4 # No Internet access, ssh server
Machine 2 (inactive connection) 10.29.70.4 # Internet access when up, no ssh server

Machine 3 (apt-cacher-ng Server) 10.29.70.10

1. Connect from 10.0.0.2 via ssh -p 2222 machine2@10.0.0.4

Problem: Once connected to Machine 2 (10.0.0.4), I can't run $ apt-get update
because there is no internet. If I was connected to 10.29.70.4, I would
do $ apt-get update (traffic is proxied to machine 3 10.29.70.10:3142)
I can't switch to the internet 10.29.70.4, it will cut my ssh connection.

I'd like to reroute traffic...
Outbound 10.0.0.4 > to apt-cacher-ng 10.29.70.10 port 3142

There are so many combinations, not sure which is most appropriate.
Virtual Interface, static route, Bridge, Ssh vpn, iptables

Thank you.

Last edited by Seemoi; 04-19-2014 at 02:18 PM.
 
Old 04-19-2014, 04:28 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,149

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
If 10.0.x.x is a private LAN with no internet access, and 10.29.70.4 can get to the internet via 10.29.70.10, then you should be able to enable both ports and have a route table something like this:

Code:
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.29.70.10     0.0.0.0         UG    0      0        0 eth1
10.29.70.0      0.0.0.0         255.255.255.0   U     0      0        0 eth1
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0

Last edited by smallpond; 04-19-2014 at 04:29 PM.
 
Old 04-19-2014, 11:13 PM   #5
Seemoi
LQ Newbie
 
Registered: Feb 2009
Posts: 29

Original Poster
Rep: Reputation: 1
Thanks smallpond.


I cannot enable the 10.29.70.4 while connected to 10.0.0.4 via ssh, it will cut the ssh connection,
there is a script in place that "service ssh stop" when 10.29.70.4 is enabled.

The gnome-network-manager is up and running.

I have experimented and achieved a result, not sure if it's the best way...

1. After ssh into 10.0.0.4, as root: $ ifconfig eth0:1 10.28.70.66 netmask 255.255.255.0 up

$ netstat -anr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.28.70.0 0.0.0.0 255.255.255.0 U 0 0 0 eth

2. apt-cacher-ng is using this in the /etc/apt/apt.conf: Acquire::http { Proxy "http://10.28.70.10:3142"; };

3. apt-get update # Success yeah !
eth0:1 as 10.28.70.66 connects to apt-cacher-ng server 10.28.70.10

I'm not sure why this works, it didn't fit into any tutorial I researched but it's working for now.
I was doing this but apparently it wasn't needed;
$ route add -host 10.28.70.10 gw 10.28.70.1 eth0:1

4. When done, delete the route for 10.28.70.0

There is only one pysical interface for each machine.

Last edited by Seemoi; 04-20-2014 at 01:46 AM.
 
Old 04-25-2014, 08:34 AM   #6
Seemoi
LQ Newbie
 
Registered: Feb 2009
Posts: 29

Original Poster
Rep: Reputation: 1
OK...

Final result, the 'only' change needed was;

1. $ ifconfig eth0:1 10.28.70.66 netmask 255.255.255.0 up
2. Edit /etc/apt/apt.conf
Acquire::http { Proxy "http://10.28.70.10:3142"; };

Routing not necessary.

Cheers !

[SOLVED]
 
  


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] [SOLVED]Force routing of packets coming from the same subnet genese Linux - Networking 2 12-29-2012 11:31 AM
IPTABLES ? - 1 ip in a different subnet push all traffic from that ip through vpn andrew44 Linux - Networking 4 07-18-2012 11:25 PM
How to force server to open connections via eth0:0 not eth0 ? Spacedust2 Linux - Newbie 1 03-03-2010 12:55 PM
[SOLVED] iptables: Block all traffic on NAT except for port 22 for eth0 Blue_Ice Linux - Security 4 01-12-2010 06:33 PM
how to limit traffic a device (eth0) using iptables? modpriest Linux - Software 1 09-04-2008 01:22 PM

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

All times are GMT -5. The time now is 03:07 PM.

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