linux不设置网关,关于设置网关的问题,刚使用linux不太明白啊...

从终端用命令设置默认网关,我上网查了资料一般用 route add default gw "网关地址"  来设置,但是我用了之后只会添加多一个default的网关。比如我用route查看得到以下信息:

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0   U     0      0        0 eth2

link-local      *               255.255.0.0     U     0      0        0 eth2

default         192.168.1.1     0.0.0.0         UG    0      0        0 eth2

我用 route add default gw 192.168.1.2 随便添加一个网关后,又多出了一个default...

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0   U     0      0        0 eth2

link-local      *               255.255.0.0     U     0      0        0 eth2

default         192.168.1.2     0.0.0.0         UG    0      0        0 eth2

default         192.168.1.1     0.0.0.0         UG    0      0        0 eth2

用一次多一个,但是默认网关不是应该只有一个的么?现在我想添加默认网关,怎么让它只会有一个对应eth2端口的?求解

|

ip route del default xxxx

ip route add default via xxxx 或者 dev eth0

|

你手动添加的 直接/etc/init.d/network reload 就没啦!

|

你现在的问题是设置网关还是需要宿主机与虚拟机ping通?

如果是需要互通,不需要设置网关的,vmware就有网关,你设置为nat即可本机通讯,如果你的网络里面有dhcp,那么设置为桥接也可以

如果是需虚拟机上网,直接设为nat也可以上网,或者设置为宿主机上网的网关,然后在 /etc/resolv.conf写上nameserver 61.147.37.1这样的dns地址

至于route 手动添加的命令

不同的系统可能有点不同

这是我的debian里面的情况

hawk@DebianYinShi{/etc} # sudo route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

hawk@DebianYinShi{/etc} # sudo route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

hawk@DebianYinShi{/etc} # sudo route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0

192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

hawk@DebianYinShi{/etc} # sudo route -F del -net 192.168.1.0/24 dev eth0

hawk@DebianYinShi{/etc} # sudo route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值