如何做到通过指定的网卡访问指定IP地址?

iwillbeback008 2015-08-10 05:16:16
我现在有个问题想请教:
我有台ubuntu的Linux的电脑有2个网卡,LAN1网卡的固定IP是10.133.10.7,LAN2网卡的固定IP是10.10.160.7,
以下是/etc/rc.local文件的内容

ip route flush table ZJZYL
ip route add default via 10.133.10.62 dev eth0 src 10.133.10.7 table ZJZYL
ip rule add from 10.133.10.7 table ZJZYL

ip route flush table VPN
ip route add default via 10.10.160.254 dev eth1 src 10.10.160.7 table VPN
ip rule add from 10.10.160.7 table VPN

/etc/network/interfaces文件的内容:
#eth0_LAN1<-->ZJZYL
auto eth0
iface eth0 inet static
address 10.133.10.7
netmask 255.255.255.192
gateway 10.133.10.62

#eth1_LAN2<-->R86 3G VPN
auto eth1
iface eth1 inet static
address 10.10.160.7
netmask 255.255.255.0
#gateway 10.10.160.254
#dns-nameservers 10.133.10.62

root@ubuntu:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.133.10.62 0.0.0.0 UG 100 0 0 eth0
10.10.160.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
10.133.10.0 0.0.0.0 255.255.255.192 U 0 0 0 eth0


LAN1连接的是一个内网,LAN2通过一个路由连接上互联网;
现在要求这个linux主机连接一个固定的公网IP A[假设为1,2,3,4]的服务器,要求访问公网IP A的数据由LAN2网卡走,但是又不能修改原来的默认网关[10.133.10.62]


总之,在不改变默认网关的情况下,如何做到通过指定的网卡访问指定IP地址?
...全文
3695 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
iwillbeback008 2015-08-17
  • 打赏
  • 举报
回复
给个例子咯 谢谢
net猎影 2015-08-12
  • 打赏
  • 举报
回复
写一条去往公网ip的路由 指向lan2口的网关
iwillbeback008 2015-08-12
  • 打赏
  • 举报
回复
没有人关注? 自己顶一下
bobochiu 2015-08-12
  • 打赏
  • 举报
回复
网关只能有一个,加一条定向路由即可

19,619

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧