centos fedora_如何在Fedora / CentOS Linux中使用CLI设置静态IP地址

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

datacenter-servers.jpg

编辑接口的配置文件 (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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值