CentOS 7 设置开机自动联网及配置静态 IP
<p><span style="font-size: 14px; font-family: "courier new", courier">CentOS 安装完成之后默认是关闭网络连接的,每次重启之后还要重新打开网络连接,比较麻烦.我们可以直接设置成开机自动连接网络.</span></p><p><strong><span style="font-size: 14px; font-family: "courier new", courier">1、首先查看网卡信息</span></strong></p>
<p><span style="font-size: 14px; font-family: "courier new", courier">使用 ifconfig 命令查看,这里的网卡名称是 ens33</span></p>
<p><span style="font-size: 14px; font-family: "courier new", courier"><img src="https://img2020.cnblogs.com/blog/1636535/202102/1636535-20210219112137864-737174825.png"></span></p>
<p><strong><span style="font-size: 14px; font-family: "courier new", courier">2、进入目录 /etc/sysconfig/network-scripts</span></strong></p>
<p><span style="font-size: 14px; font-family: "courier new", courier">该目录下放置了很多网络配置文件,你需要找到与你相对应的网口的配置文件来设置,我这里的网卡是 ens33 ,所以我们只需要修改 ifcfg-ens33 这个配置文件即可</span></p>
<p><span style="font-size: 14px; font-family: "courier new", courier"><img src="https://img2020.cnblogs.com/blog/1636535/202102/1636535-20210219112215883-2105871583.png"></span></p>
<p><strong><span style="font-size: 14px; font-family: "courier new", courier">3、修改 ifcfg-ens33 配置文件</span></strong></p>
<p><span style="font-size: 14px; font-family: "courier new", courier">需要 sudo ,或者 root 用户权限,由于我这边是 root 用户,所以直接修改即可</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:java;gutter:true;"><span style="font-size: 12px; font-family: "courier new", courier">vim ifcfg-ens33
</span></pre>
</div>
<p><span style="font-size: 14px; font-family: "courier new", courier">如果你只是想设置开机自动连接网络,只需要将 ONBOOT=no 改成 ONBOOT=yes 即可</span></p>
<p><span style="font-size: 14px; font-family: "courier new", courier"><img src="https://img2020.cnblogs.com/blog/1636535/202102/1636535-20210219112448062-2115128724.png"></span></p>
<p><strong><span style="font-size: 14px; font-family: "courier new", courier">4、</span><span style="font-size: 14px; font-family: "courier new", courier">虚拟机的 NAT 模式连接 centos7 配置静态 IP 连接外网</span></strong></p>
<p><span style="font-size: 14px; font-family: "courier new", courier">具体配置方式可以参考:<strong>https://blog.csdn.net/u011334954/article/details/96432008</strong></span></p>
<p><span style="font-size: 14px; font-family: "courier new", courier">在默认的网络配置中, IP 一般设置成 dhcp ,也就是动态 IP,可是动态的 IP 不利于端口的映射配置,所以需要把动态 IP 设置成静态 IP</span></p>
<p><span style="font-size: 14px; font-family: "courier new", courier">这里我们只需要修改如下的两处配置即可</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:java;gutter:true;"><span style="font-size: 12px; font-family: "courier new", courier">TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static# 将原先的 dhcp 改成 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=em1
UUID=5061354e-5fd7-45df-96d5-2d8f2751c66f
DEVICE=em1
ONBOOT=yes# 将原先的 no 改成 yes
# 加入以下配置
IPADDR=192.168.141.128 # 静态 IP (通过 ifconfig 查询到的本机 IP)
GATEWAY=192.168.141.2 # 自己的网关
NETMASK=255.255.255.0 # 子网掩码
DNS1=192.168.141.2 # DNS 配置,与网关保持一致</span></pre>
</div>
<p><strong><span style="font-size: 14px; font-family: "courier new", courier">5、重启网络服务</span></strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:java;gutter:true;"><span style="font-size: 12px; font-family: "courier new", courier">systemctl restart network.service
</span></pre>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>转载: https://www.jianshu.com/p/45d68c18edfc</p><br><br>
来源:https://www.cnblogs.com/xiaomaomao/p/14415293.html
頁:
[1]