centos7配置hostname和ip地址(永久有效)

一、修改hostname
1、查看当前hostname
[root@localhost~]# hostname
localhost
2、配置新主机名
[root@localhost~]# hostnamectl set-hostnametest88
3、修改/etc/hosts文件并保存
[root@localhost~]# vim /etc/hosts
127.0.0.1localhost localhost.localdomain localhost4 localhost4.localdomain4 test88
::1localhost localhost.localdomain localhost6 localhost6.localdomain6
~
:wq
二、修改ip地址
1、查看本机网卡信息
[root@test00 ~]# ifconfig
enp0s3: flags=4163mtu 1500
inet 192.168.3.253netmask 255.255.255.0broadcast 192.168.3.255
inet6 fe80::dfec:d75c:a23c:244dprefixlen 64scopeid 0x20
ether 08:00:27:13:b7:01txqueuelen 1000(Ethernet)
RX packets 184780bytes 266278597 (253.9 MiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 30875bytes 1943437 (1.8 MiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0

lo: flags=73mtu 65536
inet 127.0.0.1netmask 255.0.0.0
inet6 ::1prefixlen 128scopeid 0x10
looptxqueuelen 1000(Local Loopback)
RX packets 405bytes 29144 (28.4 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 405bytes 29144 (28.4 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0

virbr0: flags=4099mtu 1500
inet 192.168.122.1netmask 255.255.255.0broadcast 192.168.122.255
ether 52:54:00:74:a9:adtxqueuelen 1000(Ethernet)
RX packets 0bytes 0 (0.0 B)
RX errors 0dropped 0overruns 0frame 0
TX packets 0bytes 0 (0.0 B)
TX errors 0dropped 0 overruns 0carrier 0collisions 0

2、编辑对应的网卡文件
[root@test00 ~]#vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=7f12b8fc-f9d4-4908-8192-3e0f26a7c718
ONBOOT=yes
IPADDR=192.168.3.253!!!!!!!!!!!
PREFIX=24
GATEWAY=192.168.3.1
DNS1=8.8.8.8
~
修改对应的ip地址,保存退出

3、重启网络服务即可生效
[root@test00 ~]# systemctl restartnetwork

【centos7配置hostname和ip地址(永久有效)】转载于:https://www.cnblogs.com/lyz108/p/10294146.html

    推荐阅读