CentOS7设置hostname、hosts、静态IP地址、关闭防火墙

针对新安装或者克隆后的虚拟机配置

1. 设置hostname

方法1:

centos7 里面修改hostname的方式有所改变,修改/etc/hosts和/etc/sysconfig/network两个文件已经不能生效。使用的新命令是: 

[root@hadoop101 mort]# hostnamectl set-hostname hadoop101.com
[root@hadoop101 mort]# hostname -f
hadoop101.com

方法2:

修改配置文件/etc/hostname来实现主机名的修改。把该文件内容hostname name中的name替换成自己想要的主机名重启即可。

[root@hadoop101 mort]# vim /etc/hostname
hadoop101.com

centos7之前的版本请用此方法:

[root@hadoop101 mort]# vi /etc/sysconfig/network
#Created by anaconda
NETWORKING=yes
GATEWAY=192.168.1.2
HOSTNAME=hadoop101.com

2. 设置/etc/hosts

[root@hadoop101 mort]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.100 hadoop100.com hadoop100
192.168.1.101 hadoop101.com hadoop101
192.168.1.102 hadoop102.com hadoop102
192.168.1.103 hadoop103.com hadoop103
192.168.1.104 hadoop104.com hadoop104
192.168.1.105 hadoop105.com hadoop105
192.168.1.106 hadoop106.com hadoop106

3.设置静态IP

1)通过ifconfig查看网络信息,记录MAC地址

[root@hadoop101 jdk1.8.0_121]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.101  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fef1:82f0  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f1:82:f0  txqueuelen 1000  (Ethernet)
        RX packets 148611  bytes 194668379 (185.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17002  bytes 2111219 (2.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2)编辑vi /etc/sysconfig/network-scripts/ifcfg-ens33

(注意:克隆的机器的网卡地址HWADRR要与ifconfig统一)

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
NM_CONTROLLED=yes
DEFROUTE=yes
IPV6INIT=no
NAME=ens33
UUID=98af9087-41c0-43e0-8696-580bd991a0e4
DEVICE=ens33
ONBOOT=yes
HWADDR=00:0C:29:F1:82:F0
IPADDR=192.168.1.101
PREFIX=24
NETMASK=255.255.255.0
GATEWAY=192.168.1.2
DNS1=8.8.8.8
IPV4_FAILURE_FATAL=no

3)编辑vi /etc/resolv.conf

vi /etc/resolv.conf
nameserver 8.8.8.8

4)编辑vi /etc/sysconfig/network

[root@hadoop101 jdk1.8.0_121]# vi /etc/sysconfig/network 
# Created by anaconda
NETWORKING=yes
GATEWAY=192.168.1.2

5)重启网络服务

systemctl restart network.service

6)关闭防火墙

systemctl stop firewalld.service   #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state          #查看防火墙状态

4. 重启后生效

 

【若出现ifconfig中没有ens33情况】

是CentOS图形管理中的NetworkManager接管了网络配置, 执行以下命令关闭、重启网络服务:

ifconfig ens33 up
systemctl stop NetworkManager
systemctl disable NetworkManager
ifup ens33
systemctl restart network.service

  

posted @ 2019-08-13 16:48  猫不夜行  阅读(6538)  评论(1编辑  收藏  举报