温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

linux配置网关提示网络不可达怎么解决

发布时间:2020-07-02 09:50:48 来源:亿速云 阅读:5776 作者:Leah 栏目:建站服务器

linux配置网关提示网络不可达怎么解决?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

linux配置网关提示网络不可达

route: SIOCADDRT: Network is unreachable

原因:有可能是配置ip地址时,子网掩码没有加上

解决:重新配置ip,加上子网掩码,添加网关即可

具体操作过程如下:

1、添加网卡,配置ip

[root@vm50 ~]# nmcli connection show //查看网卡

名称 UUID 类型 设备

eth0 4f5f8b5d-4b51-4e1c-98c7-40f0eb90f241 802-3-ethernet eth0
virbr0 566dccb2-cbb0-4bbe-a714-06f3d313d9cd bridge virbr0
[root@vm50 ~]# nmcli connection add con-name eth2 type ethernet ifname eth2   //添加网卡
连接“eth2”(4cb9f43e-77d6-455f-990c-620e4a12d52b) 已成功添加。

[root@vm50 ~]# nmcli connection modify eth2 ipv4.method manual  ipv4.addresses 192.168.2.50/24 con.autoconnect yes  // 配置ip地址,此处192.168.2.50/24(24未加,则网络不可达)
[root@vm50 ~]# nmcli connection up eth2    /激活网卡
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/8)
[root@vm50 ~]# nmcli connection show
名称    UUID                                  类型            设备   
eht1    4cb9f43e-77d6-455f-990c-620e4a12d52b  802-3-ethernet  eth2          //已经添加的网卡
eth0    4f5f8b5d-4b51-4e1c-98c7-40f0eb90f241  802-3-ethernet  eth0   
virbr0  566dccb2-cbb0-4bbe-a714-06f3d313d9cd  bridge          virbr0

2、配置网关

[root@mysql51 ~]# systemctl stop NetworkManager    //配置网关,需先停止网络管理   
[root@mysql51 ~]# route -n                  //查看网关Gateway       
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.4.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@mysql51 ~]# route add default gw 192.168.4.50                 
    route: SIOCADDRT: Network is unreachable    //配置网关,出现网络不可达,重新配置ip
[root@mysql51 ~]# route add default gw 192.168.4.50
[root@mysql51 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.4.50    0.0.0.0         UG    0      0        0 eth0       
192.168.4.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

看完上述内容,你们掌握linux配置网关提示网络不可达的解决方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI