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 10-05-2015, 04:53 AM   #1
enri_duran
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
IP rule not work, the kernel only look up in main table


I need to make a routing using the IP source address. I want the traffic received with source IP 192.168.3.0/24 and destination IP 192.168.2.0/24 is routed through eth0 interface. I am using the kernel versin 3.16.0-30-generic. I modified the file /proc/sys/net/ipv4/ip_forward to 1. After I used:

Code:
# echo 200 virt1 >> /etc/iproute2/rt_tables
# ip rule add from 192.168.3.0/24 table virt1
# ip route add 192.168.2.0/24 dev eth0 tab virt1
Code:
# ip rule list
0:  from all lookup local 
32765:  from 192.168.3.0/24 lookup virt1 
32766:  from all lookup main 
32767:  from all lookup default

I deleted the default route. Now the main routing table is:
Code:
# ip route show table main
172.16.1.0/24 dev eth1  proto kernel  scope link  src 172.16.1.1 
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.1
To test whether it work I use socket type SOCK_RAW, with fields of the IP packet
Code:
iph->saddr = inet_addr ("192.168.3.4");
iph->daddr = inet_addr ("192.168.2.50");
If I run this, I get "Sendto: Network is unreachable". However, if you use the main table:
# ip rule add from 192.168.3.0/24 table main
# ip route add 192.168.2.0/24 dev eth0 tab main

The packet is sent

Last edited by enri_duran; 10-05-2015 at 05:08 AM.
 
Old 10-07-2015, 07:34 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
You are aware that routing decisions are only for what is leaving the machine not for what interface it is coming in on. Inbound is controlled by where you are plugged into not what you have setup on your machine.
 
Old 10-15-2015, 04:32 AM   #3
enri_duran
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Finally I got it work. The problem is that you have to put the IP address of next hop.
Code:
# echo 200 virt1 >> /etc/iproute2/rt_tables
# ip rule add from 192.168.3.0/24 table virt1
# ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0 tab virt1
 
  


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] iproute2 in Debian lenny adds routes to the main table instead of desired table donalbane Linux - Networking 3 03-28-2012 11:01 AM
[SOLVED] make: *** No rule to make target `main.c', needed by `main.o'. Stop. renjith007 Linux - Newbie 3 02-07-2012 01:08 AM
"ip route flush table main" doesn't work correctly from rc.local? gleemer Linux - Networking 0 08-17-2011 05:03 PM
No rule to make target `init/main.o' Nunana Fedora 4 03-18-2007 06:04 AM
Swap Won't Work in New 2.6.6 Kernel, Partition Table Messed Up DvChWi Slackware 11 06-19-2004 12:51 AM

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

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