温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS 7.x NAT模式上网配置的方法

发布时间:2022-05-07 15:33:53 来源:亿速云 阅读:155 作者:iii 栏目:大数据

本篇内容介绍了“CentOS 7.x NAT模式上网配置的方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

本机环境介绍如下:

  • 虚拟机版本——vmware workstation pro 12.x

  • 系统镜像——centos-7-x86_64-dvd-1511.iso

  • static ip address——10.0.0.102

  • netmask——10.0.0.2

一 vmware 配置

在“编辑”选项卡中,选择“虚拟网络编辑器”

选择vmnet8,修改子网ip与子网掩码,注意不要给“使用本地dhcp服务将ip地址分配给虚拟机”选项打勾:

点击nat设置,编辑内容如下:

设置完毕后,应用所修改的设置

二 配置网卡配置文件

登录centos7- x86_64系统,编辑网卡配置文件。

注意:centos7.x 的默认网卡文件为ifcfg-eno16777736,用户可以选择在安装系统前添加如下信息:

net.ifnames=0 net.biosdevname=0

添加信息完成后,直接回车开始安装操作系统。

原始配置文件信息:

# 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"

实现nat上网需要修改如下信息:

bootproto=static #原始值“dhcp”,改为“static”
ipaddr=10.0.0.102 #添加nat上网的静态ip地址
netmask=255.255.255.0 #添加子网掩码
gateway=10.0.0.2 #添加网关,根据vmware 软件‘虚拟网络编辑器'中的子网配置
dns1=10.0.0.2 #添加首选dns服务器
dns2=223.5.5.5 #添加备用dns服务器
onboot=yes #原始值“no”,改为“yes”,意为网卡eth0随开机启动

修改后的网卡配置文件信息:

# 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"

修改完成后,重启网络服务:

/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模式上网配置完成

ping通网络之后,可以下载需要的软件应用。

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、关闭 networkmanager 和防火墙

# systemctl disable firewalld 
# systemctl disable networkmanager

3、关闭并确认 selinux 处于关闭状态

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

4、更新系统并重启

# yum update -y && reboot

四 vmware fusion nat上网设置

1、使用iterms编辑文件

需求是通过虚拟机设置的网络号上网,所以修改vmnet8的netmask和subnet两项即可;修改后的文件内容如下:

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、设置虚拟机的网卡信息

修改文件内容,同本文第二部分修改后的网卡配置。此处不在复制粘贴。

注意:这里在修改网卡配置文件的时候,看一下mac路径内nat.conf配置文件,里面有记录修改后ip段的网关地址!我刚从这个坑里爬出来哦。

3、其他基本设置

同本文第二三部分内容,设置即可。

“CentOS 7.x NAT模式上网配置的方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI