【VMware】

设置“网络适配器”,修改“网络连接”为“桥接模式”,即直接连接物理网络。

【Ubuntu】

以Ubuntu18.04为例。

修改network-manager文件,配置相关网络参数。

root@ubuntu:~# cd /etc/netplan/ ; ls
01-network-manager-all.yaml
root@ubuntu:/etc/netplan# cp 01-network-manager-all.yaml 01-network-manager-all.yaml.ori
root@ubuntu:/etc/netplan# vim 01-network-manager-all.yaml
root@ubuntu:/etc/netplan# cat 01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
        version: 2
        renderer: NetworkManager
        ethernets:
                ens33:
                        dhcp4: no
                        dhcp6: no
                        addresses: [***.***.***.28/24]
                        gateway4: 192.168.1.1
                        nameservers:
                                addresses: [192.168.1.1, 8.8.8.8, 8.8.4.4]

具体修改内容如下。

root@ubuntu:/etc/netplan# diff 01-network-manager-all.yaml 01-network-manager-all.yaml.ori 
3,12c3,4
<         version: 2
<         renderer: NetworkManager
<         ethernets:
<                 ens33:
<                         dhcp4: no
<                         dhcp6: no
<                         addresses: [***.***.***.28/24]
<                         gateway4: 192.168.1.1
<                         nameservers:
<                                 addresses: [192.168.1.1, 8.8.8.8, 8.8.4.4]
---
>   version: 2
>   renderer: NetworkManager

启用配置。

root@ubuntu:/etc/netplan# netplan apply
root@ubuntu:/etc/netplan# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet ***.***.***.28  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fee1:8ffc  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e1:8f:fc  txqueuelen 1000  (Ethernet)
        RX packets 473  bytes 419109 (419.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 383  bytes 39589 (39.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 191  bytes 13525 (13.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 191  bytes 13525 (13.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

【CentOS】

以CentOS7为例。

修改系统对应网络接口文件(一般为/etc/sysconfig/network-scripts/目录下的第一个文件),配置相关网络参数。

[root@centos ~]# cd /etc/sysconfig/network-scripts/ ; ls
ifcfg-ens33  ifdown-ib    ifdown-ppp       ifdown-tunnel  ifup-ib    ifup-plusb   ifup-Team         network-functions
ifcfg-lo     ifdown-ippp  ifdown-routes    ifup           ifup-ippp  ifup-post    ifup-TeamPort     network-functions-ipv6
ifdown       ifdown-ipv6  ifdown-sit       ifup-aliases   ifup-ipv6  ifup-ppp     ifup-tunnel
ifdown-bnep  ifdown-isdn  ifdown-Team      ifup-bnep      ifup-isdn  ifup-routes  ifup-wireless
ifdown-eth   ifdown-post  ifdown-TeamPort  ifup-eth       ifup-plip  ifup-sit     init.ipv6-global
[root@centos network-scripts]# cp ifcfg-ens33 ifcfg-ens33.ori
[root@centos network-scripts]# vim ifcfg-ens33
[root@centos network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="526fb79d-f22c-4044-872e-cbc256ab3893"
DEVICE="ens33"
ONBOOT="yes"
IPV6_PRIVACY="no"
IPADDR=***.***.***.29
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=192.168.1.1
DNS2=8.8.8.8
DNS3=8.8.4.4

具体修改内容如下。

[root@centos network-scripts]# diff ifcfg-ens33 ifcfg-ens33.ori 
4c4
< BOOTPROTO="static"
---
> BOOTPROTO="dhcp"
17,22d16
< IPADDR=***.***.***.29
< GATEWAY=192.168.1.1
< NETMASK=255.255.255.0
< DNS1=192.168.1.1
< DNS2=8.8.8.8
< DNS3=8.8.4.4

启用配置。

[root@centos network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]
[root@centos network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet ***.***.***.29  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::bf5e:81dd:52d8:69a5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:74:87:62  txqueuelen 1000  (Ethernet)
        RX packets 2302  bytes 173370 (169.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 840  bytes 146853 (143.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 336  bytes 37296 (36.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 336  bytes 37296 (36.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:68:5b:98  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

【注意事项】

①VMware网络适配器选择桥接模式。

②修改系统文件保持谨慎最好先备份再修改。

③设置的静态IP须为当前网络中的有效IP(既在网络范围内又不与其他主机IP冲突)否则配置无法生效。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐