Linux网络配置的三种方法,手把手教你,一看就会!
Linux 三种网络配置方法详解
1. 桥接模式
虚拟机的网卡桥接到真实机的网卡
右击当前虚拟机,点击 设置
![](https://upload-images.jianshu.io/upload_images/24563956-b6b7d36ca9c5c339.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
网络适配器选择为桥接模式
![](https://upload-images.jianshu.io/upload_images/24563956-47d5b966f473db82.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
虚拟网络编辑
这里应该自动是桥接模式,但是如果修改过的要一样要修改回桥接模式, 下面的报错信息极有可能就是这里没修改造成的!!!
还有一点,桥接模式这里最好自己选择对应的网络名称,我之前选择的自动不太好使。。
在最后进行ping的时候报错:From 192.168.1.xxx icmp_seq=1 Destination Host Unreachable
![](https://upload-images.jianshu.io/upload_images/24563956-2c6eae984c135c49.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-3308b918bb5d6175.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
查看本机IP地址
![](https://upload-images.jianshu.io/upload_images/24563956-8f53b660e6940f85.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
选择你本地连接的网络,右击 状态 > 详细信息 ,就可以看到本机IP地址。比如,我的IP地址为 192.168.1.111
这里网络下面那个名称就是上一步选择的桥接到xxx
![](https://upload-images.jianshu.io/upload_images/24563956-9fefd4e8b3ce48d1.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-a3ea910273cbea28.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后在虚拟机进行配置
![](https://upload-images.jianshu.io/upload_images/24563956-cd6067b6b4439722.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-88322b298582102d.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
设置IP地址等,然后点击 Apply
![](https://upload-images.jianshu.io/upload_images/24563956-899afc0dcbd2c576.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
开启网卡
![](https://upload-images.jianshu.io/upload_images/24563956-100bac6557b7c71b.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
可以看到 IP 地址就是刚才手动配置的
![](https://upload-images.jianshu.io/upload_images/24563956-7aca0528ccd7a6af.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
虚拟机和本机互ping一下,能连通就ok了
![](https://upload-images.jianshu.io/upload_images/24563956-39fb4bb6abdb9af0.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-417206c3ed3a54b5.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2. NAT模式
虚拟网络编辑器和虚拟机网络适配器都选择为 NAT 模式
![](https://upload-images.jianshu.io/upload_images/24563956-8a8ce2120d784416.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-7d5dd8016ede236e.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
虚拟机网络设置
![](https://upload-images.jianshu.io/upload_images/24563956-cb23fa5258568e41.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
重开一下网络,这时候就可以看到自动获取的地址
![](https://upload-images.jianshu.io/upload_images/24563956-8cc64163cb236ca3.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
ping 一下外网,能 ping 通就没问题了
这里有可能会显示 ping 不通,可能是图形界面的问题,图形界面反应太慢了,重新配置一下应该就没问题了
3. 仅主机模式
装完vm软件的时候,默认会在本地安装两个网卡 【VMnet1】(仅本地模式)【VMnet8】(NAT使用),我们找到VMnet1,右键点击 属性 ,然后手动设一下IP地址
当你在本机打开适配器选项的时候可能会发现只有VMnet8,没有VMnet1,又或者二者都没有,就跟我的一样,如下图
![](https://upload-images.jianshu.io/upload_images/24563956-7d26770460636688.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
不要慌,先把虚拟机关机,然后操作如下图
![](https://upload-images.jianshu.io/upload_images/24563956-a2637cf5d4c9d6f8.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-0c9a3835a4ab5779.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
稍等一会,然后你就发现VMnet1出现了
![](https://upload-images.jianshu.io/upload_images/24563956-7e0b8c6772c31e00.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-ad97caf1d238fe9c.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
找到IPv4,双击打开,手动设置一个,确认即可
![](https://upload-images.jianshu.io/upload_images/24563956-adb218b25771aadf.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后和上面一样,我们要把虚拟机的适配器也设置为 仅主机模式
![](https://upload-images.jianshu.io/upload_images/24563956-4be6c63aa08e0f65.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
也可以选择自定义
![](https://upload-images.jianshu.io/upload_images/24563956-b622e2a3beb2dbfd.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后修改虚拟机的网络配置
![](https://upload-images.jianshu.io/upload_images/24563956-8fee83c0aabe6e13.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后重启一下网络,互 ping 一 下,能 ping 通就ok了
![](https://upload-images.jianshu.io/upload_images/24563956-fc78c02ae86884d9.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/24563956-0f6c72835baefb1b.png!web?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后
特别推荐一个分享C/C++和算法的优质内容,学习交流,技术探讨,面试指导,简历修改...还有超多源码素材等学习资料,零基础的视频等着你!
还没关注的小伙伴,可以长按关注一下:
![](https://upload-images.jianshu.io/upload_images/24563956-58c3b7df38c0da83.gif?imageMogr2/auto-orient/strip)
文章来源:https://blog.csdn.net/qq_29339467/article/details/108952531