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 07-16-2018, 04:26 PM   #1
skierinavon
LQ Newbie
 
Registered: Jul 2018
Posts: 2

Rep: Reputation: Disabled
Debian Linux - add static route - to secondary IP address on single ethernet card


Debian - I need to add a static (ipv4) route - to the secondary/static IP address on a single ethernet card.

Working: Success in adding a secondary TCP/IP address to a single ethernet card.

Working and Pinging: 192.168.1.3 & 10.22.1.3 and pinging 10.22.2.1

# Working:
# The primary network interface
allow-hotplug enp0s25
auto enp0s25:0
iface enp0s25:0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.4.4 8.8.8.8 10.22.1.1

auto enp0s25:1
iface enp0s25:1 inet static
address 10.22.1.3
netmask 255.255.255.0
gateway 10.22.1.1
dns-nameservers 8.8.4.4 8.8.8.8 10.22.1.1

The Problem: making the new (static route below) to use the secondary IP address/pathway with this:

up route add -net 10.2.10.0 netmask 255.255.255.0 gw 10.21.1.1 dev enp0s25:1

The Problem: Debian Linux still wants to use the original gateway (192.168.1.1) on the first static IP address to find it's way to 10.2.10.0

Any suggestions on how to write my "up route add -net" syntax - to make Debian use that secondary address?

thanks,
-pete
 
Old 07-18-2018, 03:04 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi

I've set up similar things, but I didn't use more than one route. As I understand it, the gateway/route is used for ip addresses outside of the netmasks of all interfaces.

And 10.2.10.0 is outside the netmask of 10.22.1.3/255.255.255.0, so it will go to the 192.168.1.1.

I would simply drop the gateway in the secondary interface, and use 255.0.0.0 as netmask. Then all traffic to 10.* will go to the secondary interface, and isn't that ok? The gateway at 192.168.1.1 will probably reject all traffic to 10.* anyway.

Edit:

If you really need two routes, and 10.2 is a different router, you really need two routes. Here's a solution:

https://unix.stackexchange.com/quest...nd-connections

Last edited by Guttorm; 07-18-2018 at 03:13 AM.
 
Old 07-18-2018, 09:22 AM   #3
skierinavon
LQ Newbie
 
Registered: Jul 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
Routing Tip WORKED!!!

Thanks Guttorm!

Your Routing suggesting works perfectly from the Secondary IP (10.x.x.x) subnet.
I can now reach my private network (10.x.x.x) and still maintain a connection to the Internet (192.168.1.x) from the Primary IP on the single Ethernet card.
Now WHY didn't I think of that??? - change the network 10 Mask to 255.0.0.0 and remove any reference to a Network 10.x.x.x Gateway on the secondary IP.

Brilliant!

Thanks again!
 
  


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
Why static routes set using 'ip route add' and 'route add' commands are not used for routing packets within the same network? kanak@tetcos.com Linux - Networking 7 04-25-2017 05:52 AM
add static route with ip command mattholm Linux - Newbie 2 01-24-2013 05:11 PM
Add route to 1 IP Address through second network card mattttux Linux - Networking 1 09-08-2010 05:31 AM
Multi IP Address to Single ethernet card scratch09 Linux - Networking 4 02-22-2005 10:22 PM

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

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