溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS 7.x NAT模式上網(wǎng)配置的方法

發(fā)布時(shí)間:2022-05-07 15:33:53 來源:億速云 閱讀:165 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“CentOS 7.x NAT模式上網(wǎng)配置的方法”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

本機(jī)環(huán)境介紹如下:

  • 虛擬機(jī)版本——vmware workstation pro 12.x

  • 系統(tǒng)鏡像——centos-7-x86_64-dvd-1511.iso

  • static ip address——10.0.0.102

  • netmask——10.0.0.2

一 vmware 配置

在“編輯”選項(xiàng)卡中,選擇“虛擬網(wǎng)絡(luò)編輯器”

選擇vmnet8,修改子網(wǎng)ip與子網(wǎng)掩碼,注意不要給“使用本地dhcp服務(wù)將ip地址分配給虛擬機(jī)”選項(xiàng)打勾:

點(diǎn)擊nat設(shè)置,編輯內(nèi)容如下:

設(shè)置完畢后,應(yīng)用所修改的設(shè)置

二 配置網(wǎng)卡配置文件

登錄centos7- x86_64系統(tǒng),編輯網(wǎng)卡配置文件。

注意:centos7.x 的默認(rèn)網(wǎng)卡文件為ifcfg-eno16777736,用戶可以選擇在安裝系統(tǒng)前添加如下信息:

net.ifnames=0 net.biosdevname=0

添加信息完成后,直接回車開始安裝操作系統(tǒng)。

原始配置文件信息:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
type=ethernet
bootproto=dhcp
defroute=yes
peerdns=yes
peerroutes=yes
ipv4_failure_fatal=no
#ipv6init=yes
#ipv6_autoconf=yes
#ipv6_defroute=yes
#ipv6_peerdns=yes
#ipv6_peerroutes=yes
#ipv6_failure_fatal=no
name=eth0
uuid=db47cec1-8f63-470f-a7ce-78dc1abf9a50
device=eth0
onboot=no
"/etc/sysconfig/network-scripts/ifcfg-eth0"

實(shí)現(xiàn)nat上網(wǎng)需要修改如下信息:

bootproto=static #原始值“dhcp”,改為“static”
ipaddr=10.0.0.102 #添加nat上網(wǎng)的靜態(tài)ip地址
netmask=255.255.255.0 #添加子網(wǎng)掩碼
gateway=10.0.0.2 #添加網(wǎng)關(guān),根據(jù)vmware 軟件‘虛擬網(wǎng)絡(luò)編輯器'中的子網(wǎng)配置
dns1=10.0.0.2 #添加首選dns服務(wù)器
dns2=223.5.5.5 #添加備用dns服務(wù)器
onboot=yes #原始值“no”,改為“yes”,意為網(wǎng)卡eth0隨開機(jī)啟動

修改后的網(wǎng)卡配置文件信息:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
type=ethernet
bootproto=static
ipaddr=10.0.0.102
netmask=255.255.255.0
gateway=10.0.0.2
dns1=10.0.0.2
dns2=223.5.5.5
defroute=yes
peerdns=yes
peerroutes=yes
ipv4_failure_fatal=no
#ipv6init=yes
#ipv6_autoconf=yes
#ipv6_defroute=yes
#ipv6_peerdns=yes
#ipv6_peerroutes=yes
#ipv6_failure_fatal=no
name=eth0
uuid=db47cec1-8f63-470f-a7ce-78dc1abf9a50
device=eth0
onboot=yes
"/etc/sysconfig/network-scripts/ifcfg-eth0"

修改完成后,重啟網(wǎng)絡(luò)服務(wù):

/etc/init.d/network restart

測試連通性:

\# ping www.baidu.com
ping www.baidu.com (119.75.218.70) 56(84) bytes of data.
64 bytes from 119.75.218.70: icmp_seq=1 ttl=128 time=82.5 ms
64 bytes from 119.75.218.70: icmp_seq=2 ttl=128 time=5.04 ms
64 bytes from 119.75.218.70: icmp_seq=3 ttl=128 time=84.7 ms
64 bytes from 119.75.218.70: icmp_seq=4 ttl=128 time=74.8 ms
64 bytes from 119.75.218.70: icmp_seq=5 ttl=128 time=24.9 ms
64 bytes from 119.75.218.70: icmp_seq=6 ttl=128 time=72.5 ms
^c64 bytes from 119.75.218.70: icmp_seq=7 ttl=128 time=95.4 ms

--- www.baidu.com ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 9939ms
rtt min/avg/max/mdev = 5.043/62.879/95.452/31.495 ms
#

三 nat模式上網(wǎng)配置完成

ping通網(wǎng)絡(luò)之后,可以下載需要的軟件應(yīng)用。

1、建議安裝 epel 倉庫并安裝常用命令

# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm 
# yum install -y net-tools vim lrzsz tree screen lsof tcpdump

2、關(guān)閉 networkmanager 和防火墻

# systemctl disable firewalld 
# systemctl disable networkmanager

3、關(guān)閉并確認(rèn) selinux 處于關(guān)閉狀態(tài)

# vim /etc/sysconfig/selinux 
selinux=disabled #修改為 disable

4、更新系統(tǒng)并重啟

# yum update -y && reboot

四 vmware fusion nat上網(wǎng)設(shè)置

1、使用iterms編輯文件

需求是通過虛擬機(jī)設(shè)置的網(wǎng)絡(luò)號上網(wǎng),所以修改vmnet8的netmask和subnet兩項(xiàng)即可;修改后的文件內(nèi)容如下:

version=1,0 
answer vnet_1_dhcp yes 
answer vnet_1_dhcp_cfg_hash 7c0a6ba01faeb4aa67d79a3b663ed0cd669ebe5b 
answer vnet_1_hostonly_netmask 255.255.255.0 
answer vnet_1_hostonly_subnet 192.168.211.0 
answer vnet_1_virtual_adapter yes 
answer vnet_8_dhcp yes 
answer vnet_8_dhcp_cfg_hash 0849581b4878eb20736f9d4ff8dcb8d65d6b17ae 
answer vnet_8_hostonly_netmask 255.255.255.0 
answer vnet_8_hostonly_subnet 192.168.56.0 
answer vnet_8_nat yes 
answer vnet_8_virtual_adapter yes 
add_bridge_mapping en1 2 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
“/library/preferences/vmware fusion/networking” [readonly] 13l, 488c

2、設(shè)置虛擬機(jī)的網(wǎng)卡信息

修改文件內(nèi)容,同本文第二部分修改后的網(wǎng)卡配置。此處不在復(fù)制粘貼。

注意:這里在修改網(wǎng)卡配置文件的時(shí)候,看一下mac路徑內(nèi)nat.conf配置文件,里面有記錄修改后ip段的網(wǎng)關(guān)地址!我剛從這個(gè)坑里爬出來哦。

3、其他基本設(shè)置

同本文第二三部分內(nèi)容,設(shè)置即可。

“CentOS 7.x NAT模式上網(wǎng)配置的方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI