修改linux redhat的 hostname 其实有好一些陷阱。。html
一般 咱们修改 /etc/sysconfig/network 的 HOSTNAME 变量便可linux
可是它不会当即生效, 须要执行下面的
sysctl kernel.hostname=lk0网络
可是, 到了redhat7 , 这招都不适用了! —— 重启后 hostname 又恢复到以前的了!!ui
从http://www.2cto.com/os/201412/364303.html 了解到, 那个不适用了!this
首先须要yum groupinstall base (在光盘镜像)rest
安装完后ifconfig、service、chkconfig等命令就都有了htm
Redhat 7以前,是修改 /etc/inittab文件。接口
Redhat 7的话,查看该文件会有提示。ip
只须要在/lib/system/system/目录下建个软件连便可。rem
a) 网络管理器
RHEL 7 安装有网络管理器,并处于启动状态
b) 查看网络接口
查看网络接口。
c) 文本配置网络
在以下路径,增长文件如ifcfg-enp0s3
d) 图形化配置网络
启动图形化配置。
e) 启动网络
编辑文件
/etc/hostname
便可修改主机名。
注:RedHat7以前,编辑/etc/sysconfig/network文件。
Redhat7中使用命令 hostnamectlstatus 命令查看主机名
此外也能够在
中设置主机名
查看防火墙状态。
临时关闭防火墙命令。重启电脑后,防火墙自动起来。
systemctl stop firewalld
永久关闭防火墙命令。重启后,防火墙不会自动启动。
systemctl disable firewalld
打开防火墙命令。
systemctl enable firewalld
原来须要使用:hostnamectl
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host
具体来讲, 这样修改:
hostnamectl set-hostname lk0
ok !