linux桥接模式下配置静态ip

原文链接:http://blog.csdn.net/qq_37936542/article/details/79494993

一:桥接模式

VMware桥接模式,也就是将虚拟机的虚拟网络适配器与主机的物理网络适配器进行交接,虚拟机中的虚拟网络适配器可通过主机中的物理网络适配器直接访问到外部网络,简而言之,这就好像在局域网中添加了一台新的、独立的计算机一样。因此,虚拟机也会占用局域网中的一个IP地址,并且可以和其他终端进行相互访问。桥接模式网络连接支持有线和无线主机网络适配器。如果你想把虚拟机当做一台完全独立的计算机看待,并且允许它和其他终端一样的进行网络通信,那么桥接模式通常是虚拟机访问网络的最简单途径。

二:设置网络适配器

linux桥接模式下配置静态ip

linux桥接模式下配置静态ip


三:修改配置文件,设置静态ip

1:查看网卡接口名称  ifconfig | more 或者 ip addr | more

[html] view plain copy
  1. [[email protected] ~]# ifconfig | more  
  2. eth0      Link encap:Ethernet  HWaddr 00:0C:29:5A:71:6D    
  3.           inet addr:192.168.1.123  Bcast:192.168.1.255  Mask:255.255.255.0  
  4.           inet6 addr: fe80::20c:29ff:fe5a:716d/64 Scope:Link  
  5.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  6.           RX packets:5631 errors:0 dropped:0 overruns:0 frame:0  
  7.           TX packets:324 errors:0 dropped:0 overruns:0 carrier:0  
  8.           collisions:0 txqueuelen:1000   
  9.           RX bytes:398905 (389.5 KiB)  TX bytes:27775 (27.1 KiB)  
  10.   
  11. lo        Link encap:Local Loopback    
  12.           inet addr:127.0.0.1  Mask:255.0.0.0  
  13.           inet6 addr: ::1/128 Scope:Host  
  14.           UP LOOPBACK RUNNING  MTU:16436  Metric:1  
  15.           RX packets:230 errors:0 dropped:0 overruns:0 frame:0  
  16.           TX packets:230 errors:0 dropped:0 overruns:0 carrier:0  
  17.           collisions:0 txqueuelen:0   
  18.           RX bytes:19722 (19.2 KiB)  TX bytes:19722 (19.2 KiB)  


2:编辑网卡文件 vim /etc/sysconfig/network-scripts/ifcfg-eth0

如上图所示,我的网卡名称是eth0,那么对应的文件名称就是ifcfg-eth0

[html] view plain copy
  1. [[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0   
  2.   
  3. DEVICE=eth0   #网卡接口名称  
  4. BOOTPROTO=dhcp  #系统启动地址协议   dhcp:DHCP动态地址协议  static:静态地址协议  
  5. HWADDR=00:0c:29:5a:71:6d  
  6. IPV6INIT=yes  
  7. NM_CONTROLLED=yes  
  8. ONBOOT=yes   #系统启动时是否**网卡接口  
  9. TYPE=Ethernet  
  10. UUID="793813e9-4cbd-4ae1-a1de-f9f38b8369ee"  
  11. USERCTL=no  
  12. PEERDNS=yes  

修改BOOTPROTO和ONBOOT选项
[html] view plain copy
  1. BOOTPROTI=static  
  2. ONBOOT=yes  

然后在文件中添加如下内容

[html] view plain copy
  1. IPADDR=192.168.1.123  #静态ip,添加前先ping一下该ip,ping不通才能使用,确保唯一  
  2. NETMASK=255.255.255.0  #子网掩码  
  3. GATEWAY=192.168.1.1   #网关  

完整版配置文件如下

[html] view plain copy
  1. [[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0   
  2.   
  3. DEVICE=eth0  
  4. BOOTPROTO=static  
  5. HWADDR=00:0c:29:5a:71:6d  
  6. IPV6INIT=yes  
  7. NM_CONTROLLED=yes  
  8. ONBOOT=yes  
  9. TYPE=Ethernet  
  10. UUID="793813e9-4cbd-4ae1-a1de-f9f38b8369ee"  
  11. USERCTL=no  
  12. PEERDNS=yes  
  13. IPADDR=192.168.1.123  
  14. NETMASK=255.255.255.0  
  15. GATEWAY=192.168.1.1  

3:重启网络 service network restart
[html] view plain copy
  1. [[email protected] Desktop]# service network restart  
  2. Shutting down interface eth0:                              [  OK  ]  
  3. Shutting down loopback interface:                          [  OK  ]  
  4. Bringing up loopback interface:                            [  OK  ]  
  5. Bringing up interface eth0:  Active connection state: activating  
  6. Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/9  
  7. state: activated  
  8. Connection activated  
  9.                                                            [  OK  ]  

四:本机打开cmd进行测试 ping 192.168.1.123
[html] view plain copy
  1. C:\Windows\System32>ping 192.168.1.123  
  2.   
  3. 正在 Ping 192.168.1.123 具有 32 字节的数据:  
  4. 来自 192.168.1.123 的回复: 字节=32 时间=6ms TTL=64  
  5. 来自 192.168.1.123 的回复: 字节=32 时间=30ms TTL=64  
  6. 来自 192.168.1.123 的回复: 字节=32 时间=8ms TTL=64  
  7. 来自 192.168.1.123 的回复: 字节=32 时间=8ms TTL=64  


参考文章:点击打开链接

文末福利:

福利一:前端,Java,产品经理,微信小程序,Python等资源合集大放送:https://www.jianshu.com/p/e8197d4d9880
福利二:微信小程序入门与实战全套详细****:https://www.jianshu.com/p/e8197d4d9880


linux桥接模式下配置静态ip

领取方式:
如果需要学习视频,欢迎关注 【编程微刊】微信公众号,回复【领取资源】一键领取以下所有干货资源,获取更多有用技术干货、文档资料。所有文档会持续更新,欢迎关注一起成长!