centos fedora
How to set the static IP address for CentOS 7/Fedora 22+ is introduced in this post. Here, we assume the Linux is using NetworkManager to manage the network. All steps are done as root.
这篇文章介绍了如何为CentOS 7 / Fedora 22+设置静态IP地址。 在这里,我们假设Linux使用NetworkManager来管理网络 。 所有步骤均以root用户身份完成。
找到要设置地址的接口∞ (Find the interface you want to set the address ∞)
Command
命令
ifconfig -a
lists all interfaces.
列出所有接口。
Find the interface name to set, such as enp2s0
.
查找要设置的接口名称,例如enp2s0
。
编辑接口的配置文件∞ (Edit the interface’s configuration file ∞)
For interface NAME
, the configuration file is stored in /etc/sysconfig/network-scripts/ifcfg-NAME
. For the above example of enp2s0
, the configuration file is /etc/sysconfig/network-scripts/ifcfg-enp2s0
.
对于接口NAME
,配置文件存储在/etc/sysconfig/network-scripts/ifcfg-NAME
。 对于上面的enp2s0
示例,配置文件是/etc/sysconfig/network-scripts/ifcfg-enp2s0
。
As an example, to set its IP to 1.2.3.4 with netmask 255.255.255.0, gateway 4.3.2.1, DNS 114.114.114.114, the content will be like
例如,要将其IP设置为1.2.3.4,网络掩码为255.255.255.0,网关为4.3.2.1,DNS为114.114.114.114,其内容将类似于
NM_CONTROLLED="yes"
DEVICE="enp2s0"
BOOTPROTO=static
ONBOOT="yes"
IPADDR=1.2.3.4
NETMASK=255.255.255.0
GATEWAY=4.3.2.1
DNS1=114.114.114.114
For more details of the configuration and other options, you may check the the Interface Configuration Options from this QA.
有关配置和其他选项的更多详细信息,请检查此QA中的“接口配置选项” 。
重新启动网络/ NetworkManager服务∞ (Restart network/NetworkManager services ∞)
You will need to restart the network/Networkmanager services to make the new configuration take effect
您将需要重新启动网络/ Networkmanager服务以使新配置生效
# systemctl restart network.service
# systemctl restart NeworkManager.service
Then you can use ifconfig -a
again to verify whether the IP is set successfully.
然后,可以再次使用ifconfig -a
来验证IP是否设置成功。
翻译自: https://www.systutorials.com/how-to-set-the-static-ip-address-using-cli-in-fedoracentos-linux/
centos fedora