好好爱自己!

Route all trafic for specific ip over specific network interface

15

I have a linux server that needs to get some routing. I'm fairly new at this and i don't find any clear source on google.

The setup should be simple:
All traffic to a server on ip 192.168.72.20 should be sent over interface 3. All other interfaces don't matter at the moment.

Here you have the output for route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.72.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.72.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.72.0    0.0.0.0         255.255.255.0   U     0      0        0 eth2
192.168.72.0    0.0.0.0         255.255.255.0   U     0      0        0 eth3
192.168.72.0    0.0.0.0         255.255.255.0   U     0      0        0 eth4
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.72.12   0.0.0.0         UG    0      0        0 eth0
 
  • 1
    Are you using the old fashioned ifconfig and route command or the modern ip commands? (old ones would be something like route add -host 192.168.72.20 GW eth3_ip) – Hennes Mar 29 '13 at 13:48
20
 

Try:

ip route add 192.168.72.20/32 dev eth3

 
  • 3
    Just a note: to permanently keep this configuration make sure you add it to /etc/rc.local or your distro's equivalent. It won't persist between reboots. – LawrenceC Mar 29 '13 at 16:32
  • 1
    I tried this same format for mapping an IP to the wlan0 on Ubuntu 14.04 and got RTNETLINK answers: Invalid argument I had to remove the /** from the IP so I ended up with: sudo ip route add 192.168.50.15 dev wlan0 -- thought I'd mention that in case anyone else ran into this issue. Thank you for your answer ultrasawblade, it was helpful. – mason81 Jul 10 '15 at 14:54
posted @   立志做一个好的程序员  阅读(285)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2017-11-10 How can I add files to a Jar file? (or add a file to a zip archive)
2017-11-10 终于理解java的classpath!
2017-11-10 从一个简单的例子谈谈package与import机制
2017-11-10 java 中public 类
2017-11-10 java 内部类
2016-11-10 学习资料网站
2016-11-10 android app开发

不断学习创作,与自己快乐相处

点击右上角即可分享
微信分享提示