Linux 虚拟机网络连接

xiaoxiao2022-06-12  38

一、真机连接wifi (1)必须是root用户修改 (2)目录: /etc/sysconfig/network-scripts/ifcfg-br0 (3)进入文件 vim ifcfg-br0 (4)修改文件 注释网关 (5)重置网络

[root@foundation68 network-scripts]# systemctl restart network

二、虚拟机server使用真机wifi登陆百度 实验条件: server借助desktop(路由器)ping百度 server:1.1.1.200(eth0,添加网关:1.1.1.100) desktop:eth0添加网关(主机ip 172.25.2543.33) eth1:1.1.1.100

desktop借助server(路由器)ping百度 实验前提i:实验开始之前,需真机连接wifi并可以ping通百度 虚拟机desktop可以连接虚拟机server

(1)真机ping百度

[root@foundation68 network-scripts]# ping www.baidu.com PING www.a.shifen.com (183.232.231.172) 56(84) bytes of data. 64 bytes from 183.232.231.172 (183.232.231.172): icmp_seq=1 ttl=56 time=39.1 ms 64 bytes from 183.232.231.172 (183.232.231.172): icmp_seq=2 ttl=56 time=40.2 ms ^C --- www.a.shifen.com ping statistics --- 7 packets transmitted, 7 received, 0% packet loss, time 30150ms rtt min/avg/max/mdev = 39.167/39.986/40.855/0.679 ms [root@foundation68 network-scripts]#

(2)真机是否有网关

[root@foundation68 network-scripts]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 600 0 0 wlp3s0 172.25.68.0 0.0.0.0 255.255.255.0 U 425 0 0 br0 172.25.254.0 0.0.0.0 255.255.255.0 U 425 0 0 br0 192.168.1.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp3s0 192.168.122.0 0.0.0.0 255.255.255.0 U 425 0 0 virbr0 [root@foundation68 network-scripts]#

可以看出,真机网关为192.168.1.1(真机wifi的ip)

(3)虚拟机desktop设置 将真机ip作为网关添加进desktop中

(4)查看真机防火墙 查看防火墙过程中需要将虚拟机关闭并打开 关闭虚拟机

[root@foundation68 ~]# systemctl stop libvirtd

打开虚拟机

[root@foundation68 ~]# systemctl start libvirtd

(5)检查真机内核 在虚拟机desktop(172.25.254.168)ping不通真机(172.25.254.68)时,排除掉虚拟机ip设置错误后,ping不通的原因可能为真机内核配置文件设置有问题。

当net.ipv4.ip_forward = 1时说明真机内核设置无问题,若值为0,解决方案: 进入配置文件 [root@foundation68 ~]# vim /etc/sysctl.conf 在文件中添加一行 net.ipv4.ip_forward = 1

此防火墙与内核检查需在虚拟机desktop中再检查一遍方可保证虚拟机server可以通过desktop连跳访问到真机的网络。

(6)实验

虚拟机server使用真机wifi登陆百度成功。 排错时若同一网段的都无法ping通,那就时网卡坏了

转载请注明原文地址: https://www.6miu.com/read-4932768.html

最新回复(0)