CentOS how to fix the IP address of the Linux system, to avoid IP address changes

Author : YDD This article has 1413 words, Reading time 4 minutes Posted on: 2024-03-9 Read by 713 people
advertising chart
advertising chart
Want to show up here too?Contact us.

Article Description:

今天想连接winSCP,发现连不上,原来Linux系统的IP地址变了,为了避免IP地址的变动,我就想固定IP地址,方法如下:

1、输入ifconfig(如果CentOS是最小化安装,是没有ifconfig命令的)或ip addr ,可以查看网络相关配置信息;

CentOS如何固定Linux系统的IP地址,避免IP地址的变动-效果图1

2、输入 vi /etc/sysconfig/network-scripts/ifcfg-ens33 命令,查看网卡配置文件

3、修改网卡配置文件,按 i 键进行编辑,原有的配置不要删,只要按下图修改就好,没有的配置项新增上去就好;

CentOS如何固定Linux系统的IP地址,避免IP地址的变动-效果图2

打开以后可以看到默认的配置就是dhcp,然后onboot=no,表示不会随着系统的启动而启动。我们需要修改这个配置把onboot=no修改为:onboot=yes;

4、修改好后,按Esc键退出编辑,:wq 命令保存并退出,reboot重启;

5、reboot命令重启虚拟机;

6、重启后,输入ifconfig 或 ip addr命令,查看是IP是否修改成功;

CentOS如何固定Linux系统的IP地址,避免IP地址的变动-效果图3

整理好的参数,按需修改:
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=”4ac9950a-0658-4108-85db-029270b1e766″
DEVICE=”ens33″
ONBOOT=”yes”
IPADDR=”10.10.10.120″
NETMASK=”255.255.255.0″
GATEWAY=”10.10.10.1″
DNS1=”114.114.114.114″
DNS2=”114.114.115.115″

TYPE=Ethernet           #网卡协议类型
ONBOOT=yes              #系统启动时是否自动加载该网卡yes/no
DEVICE=“ens33”             #网卡名称
BOOTPROTO=dhcp          #获取地址协议[static静态]、[bootp协议]、[dhcp协议]
IPADDR=192.168.1.254    #IP地址
NETMASK=255.255.255.0    #IP对应的子网掩码
GATEWAY=192.168.1.1     #IP对应的网关地址
DNS1="114.114.114.114"     #指定DNS1地址
DNS2="114.114.115.115"     #备用DNS2地址

附加

CentOS 7.X 镜像下载常用命令:

ls -l 显示当前目录所有文件的创建时间(ls空格-l)

cd l 进去下一个l目录

rm * 删除当前目录下的所有

cd .. 进入上一个目录(cd空格..)

Su 普通用户切换到root

unzip wap-sp.zip 解压文件(unzip+压缩的文件名)

pwd 显示当前目录路径

mv+将要移动的文件(绝对路径)+目标目录(.表示当前目录)

Svn add 项目名 添加项目到svn再更新

svn ci -m “add” svn递交文件(svn+空格+ci(ci递交的意思)+-m(-m表示描述性说明)+”这里面是描述性语句”)

svn add edit.php paytool_* svn添加文件
advertising chart
advertising chart
Want to show up here too?Contact us.
Frequently Asked Questions FAQ
Can free downloads or VIP member-only resources be commercialized directly?
The resources on this site are collected and organized through the network, for personal research and study purposes only. The copyright belongs to the legal owner of the software and program code, users should verify the copyright and legality of the resources, prohibited for commercial use, illegal activities or any violation of national laws and regulations.
Disclaimer of liability for program or code bugs, compatibility issues or functional defects, etc.
As the resources on this site are collected and organized through the network, not the site's original, it can not fully guarantee its functionality or code compatibility. Users need to verify whether the resources meet the needs of their own, due to the following circumstances lead to losses, this site does not assume any responsibility:
Programs, source code and other computer software resources may contain code vulnerabilities (bugs), compatibility issues or functional defects left by the developer. This site does not provide free repair services for such technical defects, users need to bear the risk of debugging, modification or abandonment of the use.
© 2025 by - SourceHub & Www.ZYYdd.Com. All rights reserved 蜀ICP备2025145155号-1