Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 10-05-2015, 04:53 AM   #1
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 and destination IP 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:

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

I deleted the default route. Now the main routing table is:
# ip route show table main dev eth1  proto kernel  scope link  src dev eth0  proto kernel  scope link  src
To test whether it work I use socket type SOCK_RAW, with fields of the IP packet
iph->saddr = inet_addr ("");
iph->daddr = inet_addr ("");
If I run this, I get "Sendto: Network is unreachable". However, if you use the main table:
# ip rule add from table main
# ip route add 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
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
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.
# echo 200 virt1 >> /etc/iproute2/rt_tables
# ip rule add from table virt1
# ip route add via dev eth0 tab virt1


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:27 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration