


How to configure a static IP address on CentOS 7 using ifcfg files?
Jul 02, 2025 am 12:22 AM配置CentOS 7靜態(tài)IP地址需編輯對應(yīng)網(wǎng)卡的ifcfg文件。1.先通過ip link show或ls /sys/class/net確認(rèn)網(wǎng)卡名如ens33;2.編輯/etc/sysconfig/network-scripts/ifcfg-ens33文件設(shè)置BOOTPROTO=static并填寫IPADDR、NETMASK、GATEWAY等參數(shù);3.保存后重啟network服務(wù)使配置生效;4.用ip addr show和ping命令驗證配置是否成功。注意避免IP沖突修改后需重啟網(wǎng)絡(luò)服務(wù)若使用NetworkManager建議用nmtui工具配置。
配置 CentOS 7 的靜態(tài) IP 地址其實不復(fù)雜,關(guān)鍵是找到正確的網(wǎng)卡配置文件并正確填寫參數(shù)。CentOS 7 使用的是傳統(tǒng)的 ifcfg
文件方式來管理網(wǎng)絡(luò)接口,雖然新版本已經(jīng)轉(zhuǎn)向 nmcli
或 netplan
,但在 CentOS 7 上,還是主要靠編輯 /etc/sysconfig/network-scripts/ifcfg-<interface>
來設(shè)置靜態(tài) IP。
找到你要配置的網(wǎng)卡名稱
在開始修改配置前,先確認(rèn)你要配置的網(wǎng)絡(luò)接口名稱。常用的命令是:
ip link show
或者更簡單點:
ls /sys/class/net
常見網(wǎng)卡名有 eth0
、ens33
、enp0s3
這樣的格式。記下你要配置的那個名字。
編輯對應(yīng)的 ifcfg 文件
每個網(wǎng)卡都有一個對應(yīng)的配置文件,路徑一般是:
/etc/sysconfig/network-scripts/ifcfg-<網(wǎng)卡名>
比如你的網(wǎng)卡是 ens33
,那文件就是:
/etc/sysconfig/network-scripts/ifcfg-ens33
用你喜歡的編輯器打開它,比如:
sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
確保文件里包含以下內(nèi)容(或根據(jù)需要修改):
BOOTPROTO=static ONBOOT=yes IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4
解釋一下幾個關(guān)鍵字段:
BOOTPROTO=static
:表示使用靜態(tài) IP。ONBOOT=yes
:開機(jī)時自動啟用這個網(wǎng)卡。IPADDR
:你想要設(shè)置的 IP 地址。NETMASK
:子網(wǎng)掩碼。GATEWAY
:默認(rèn)網(wǎng)關(guān)。DNS1
和DNS2
:可選,指定 DNS 服務(wù)器。
保存退出后,重啟網(wǎng)絡(luò)服務(wù)讓配置生效:
sudo systemctl restart network
檢查是否生效
可以用下面幾個命令來驗證是否配置成功:
ip addr show ping -c 4 8.8.8.8
如果能正??吹皆O(shè)置的 IP,并且能 ping 通外網(wǎng)地址,說明配置成功。
小貼士和注意事項
- 確保不要和其他設(shè)備的 IP 沖突。
- 如果你在虛擬機(jī)中操作,注意虛擬網(wǎng)絡(luò)的模式(NAT、橋接等)會影響網(wǎng)絡(luò)連通性。
- 修改完配置后記得重啟網(wǎng)絡(luò)服務(wù),否則不會生效。
- 多個 IP 可以通過添加
IPADDR1=...
、NETMASK1=...
來實現(xiàn)。 - 如果系統(tǒng)安裝了 NetworkManager,建議使用
nmtui
工具來配置,更加直觀。
基本上就這些,別看步驟多,實際操作起來很快。只要注意網(wǎng)卡名和配置項別寫錯就行。
The above is the detailed content of How to configure a static IP address on CentOS 7 using ifcfg files?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Change the wifi static IP to 180.76.76.76 and 114.114.114.114 respectively. After modification, the DNS resolution speed will be accelerated, thereby speeding up the network speed.

LINUX is an open source operating system that is widely used in servers and embedded devices. In the server field, CentOS is a very popular LINUX distribution, and 82599 is a common high-performance network card. This article will introduce how to Install the 82599 network card driver under CentOS7, and explain in detail the steps and precautions for installing CentOS7 on the DellPowerEdge2288HV5 server. Installation of 82599 network card driver under CentOS7 1. Confirm that your CentOS7 system has been installed correctly and is in the latest status. You can use the following command to confirm the system version and update status: ```cat/etc/redhat-rele

A static IP address is an unchanging number assigned to a computer by an Internet Service Provider (ISP). It is used to temporarily identify a specific address rather than a group. Gamers who do website hosting and Voice over Internet Protocol (VoIP) services will find that static IPs work best for their activities. There are many reasons why static IP addresses are valid. For example, if you host your web or email servers, you need to have one so you can configure them. However, this is not possible with dynamic IPs as they only apply for a limited time before changing. Typically, a specific dynamic IP address is assigned to a user as long as the user's modem remains connected. However, when they disconnect and

Open KDE's settings panel First, open KDE's settings panel. You can click the settings icon on the desktop, or search for "Settings" in the start menu and open it. Click the "Network" option in the settings panel. Next, you will see a "NetworkConnections" window. In this window, you need to click the "Add" button to add a new network connection. In the CreateNewConnection dialog box, select Manual&rdquo

The most common way we use computers is to surf the Internet or search for information, but recently many of our friends have discovered a problem. When we tried to change the IP, we found that we could not set a static IP to access the Internet. In fact, it is very difficult to solve this problem. of simplicity. Win10 Home Edition cannot set a static IP for Internet access. Method: Manual setting 1. First, we open the local connection, then right-click on the properties in the pop-up window, and then select ipv4 settings. 2. Then we delete all the original settings, select Automatically obtain IP settings, and click OK. 3. After we re-obtain the ip address, we can use the ipconfig command to view the new ip address in the DOC system. 4. Then we open the local area connection properties, and we manually

1. Right-click the display icon in the lower right corner and click to open Network and Sharing Center; as shown in the figure: 2. Click Ethernet; as shown in the figure: 3. Click Properties in the new window; as shown in the figure: 4. Select Internet Protocol Version 4 (TCP/IP4), click Properties; as shown in the figure: 5. Now IP and DNS are automatic; as shown in the figure: 6. Open CMD, enter ipconfig/all, and copy the contents in the red box Go to the [Select Internet Protocol Version 4 (TCP/IP4)] window. The last segment of the IP address can be set to any number from 1 to 255. It is recommended to set it larger to avoid conflict with other users in the LAN; as shown in the figure: 7. Click OK. If the lower right corner of the computer

To configure the CentOS7 static IP address, you need to edit the ifcfg file of the corresponding network card. 1. First confirm the network card name such as ens33 through iplinkshow or ls/sys/class/net; 2. Edit the /etc/sysconfig/network-scripts/ifcfg-ens33 file to set BOOTPROTO=static and fill in IPADDR, NETMASK, GATEWAY and other parameters; 3. After saving, restart the network service to make the configuration take effect; 4. Use the ipaddrshow and ping commands to verify whether the configuration is successful. Be careful to avoid IP conflicts and restart the network service after modification. If you use NetworkM

To reset the root password of CentOS7, go to the GRUB menu and start single user mode. 1. Press the arrow keys repeatedly during startup to interrupt the startup process to enter the GRUB menu; 2. Select the kernel and press "e" to edit the startup parameters; 3. Add rd.break at the end of line 16 of Linux, and then start; 4. After entering initramfsshell, remount the root file system to read and write mode; 5. Use chroot to switch to the real root environment and use passwdroot to modify the password; 6. Create a .autorelabel file to ensure that SELinux relabel correctly; 7. Enter exit to exit and restart the system. This method requires physical or console access, and the remote server requires
