centos7配置hostname和ip地址
Posted lyz108
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7配置hostname和ip地址相关的知识,希望对你有一定的参考价值。
一、修改hostname
1、查看当前hostname
[[email protected]~]# hostname
localhost
2、配置新主机名
[[email protected]~]# hostnamectl set-hostname test88
3、修改/etc/hosts文件并保存
[[email protected]~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 test88
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
~
:wq
二、修改ip地址
1、查看本机网卡信息
[[email protected] ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.253 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::dfec:d75c:a23c:244d prefixlen 64 scopeid 0x20<link>
ether 08:00:27:13:b7:01 txqueuelen 1000 (Ethernet)
RX packets 184780 bytes 266278597 (253.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30875 bytes 1943437 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 405 bytes 29144 (28.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 405 bytes 29144 (28.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:74:a9:ad txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、编辑对应的网卡文件
[[email protected] ~]#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、重启网络服务即可生效
[[email protected] ~]# systemctl restart network
以上是关于centos7配置hostname和ip地址的主要内容,如果未能解决你的问题,请参考以下文章