代码改变世界

关闭防火墙和设置主机名和ip及克隆机网卡处理方法

2018-10-04 13:57  烟雨楼人  阅读(503)  评论(0编辑  收藏  举报

关闭防火墙:

service NetworkManager stop --图形化用ifconfig之前先关掉网络服务.

chkconfig NetworkManager off (将开机自启动关掉,使开机后也不启动.)

NetworkManager是默认开机自启动,需关掉.  没图形化上面两步不用执行.

service iptables stop   chkconfig iptables off (6里是iptables ,7里是firewalld)

service ip6tables stop   chkconfig ip6tables off

启动: systemctl start firewalld

关闭: systemctl stop firewalld

查看状态: systemctl status firewalld

开机禁用   systemctl disable firewalld

开机启用   systemctl enable firewalld

查看是否开机启用:systemctl is-enabled firewalld

[root@lbg ~]# systemctl is-enabled firewalld

disabled

关掉上面三个后查看selinux状态,临时设置selinux状态为其为disable.

查看selinux状态:getenforce .

修改selinuxdisabled:  setenforce 0.

再永久修改selinux状态为不可用:/etc/selinux/config--selinux enforcing 改为disabled.(由激进强制使用改为不可用)

 

 

修改主机名:

 临时修改主机名:hostname host_name

[root@localhost boot]# hostname

localhost.localdomain

[root@localhost boot]# hostname lbg

[root@localhost boot]# hostname

lbg

CentOS永久修改主机名方法1 vim /etc/hostname 

[root@lbg ~]# vim /etc/hostname 

CentOS永久修改主机名方法2hostnamectl set-hostname lbg

Red-Hat永久修改主机名:vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=lbg

 

查看ip:  ifconfig   或者ip  a

 [root@lbg ~]# ifconfig

[root@lbg ~]# ip a

说明:直接ifconfig 只显示激活的网卡.ifconfig -a 显示所有网卡.

eth0:  Ethernet 0第一块网卡. ...eth1 第二块网卡.  Ethernet s是以太网.

lo:local loopback 本地回环网卡.(127.0.0.1,ping的通,说明网卡没问题.在网络通讯中用不到,只用于本机内部通讯,用于检测网卡)

网卡配置文件说明:

 [root@lbg ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 

DEVICE = eth0|eth1 //设备编号

ONBOOT=yes|no //是否随系统启动而启动

HWADDR=00:0C:29:62:30:22 // MAC地址,64.16进制表示.前三段是厂商地址,后三段式厂商自己产品编号.

TYPE=Ethernet // 类型,Ethernet指以太网

BOOTPROTO=none/static/dhcp // 地址分配方式,前两种都是静态IP,后面是动态分配.如果选择了前两种,后面的IPADDR,NETMASK是必须写的

IPADDR=192.168.1.156 // IP地址

NETMASK=255.255.255.0/PREFIX=24 //子网掩码

GATEWAY=192.168.1.1 // 网关地址

DNS1=192.168.1.1 // DNS地址,可选多个,用编号区别

DEFROUTE=yes|no // 路由设置

uuid:是操作系统分配给设备的唯一编号.(设备完蛋后依旧保留.) 之所以有uuid,是为了保证识别的设备名字不因为识别顺序发生变化.(是按识别的设备的顺序命名的)

NM_CONTROLLED=yes:图形的网络管理,不用,可删除.

注:当ONBOOT设置为NO时,系统启动不会启动上面的DEVICE。需要将ONBOOT改为YES或是手动启动服务


配置网卡:

 ONBOOTyes,修改bootprotonone,删除行NM_CONTROLLed=yes(是否被network服务控制).添加IPADDRNETMASK. 配置后内容如下:

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

NAME=ens33

UUID=cace8659-ed67-457c-bfd0-ee88b4993588

DEVICE=ens33

ONBOOT=yes

IPADDR=192.168.88.8

NETMASK=255.255.255.0


激活网卡:

 先关闭防火墙:

service NetworkManager stop 

chkconfig NetworkManager off 

service iptables stop   chkconfig iptables off (6里是iptables ,7里是firewalld)

service ip6tables stop  chkconfig ip6tables off

getenforce

setenforce 0

vim /etc/selinux/config  修改enforcing 改为disabled

临时激活网卡: ifconfig eth0 up  或者  ifup eth0

临时关闭网卡: ifconfig eth0 down  或者 ifdown eth0  

再临时设置ip:  ifconfig eth0 192.168.88.8    netmask 255.255.255.0

永久设置ip:  vim     /etc/sysconfig/network-scripts/ifcfg-eth0

重启网络服务: service Network restart 


临时添加多个
ip,命令如下:

 Ifconfig eth0 192.168.88.100/24 up --激活并设置ip.

Ifconfig eth0:0 192.168.100.100/24 up --添加第二个ip.

eth0:x    //虚拟网络接口,建立在eth0上,取值范围0-255


说明:也可用setup命令伪图形化设置ip. [root@lbg ~]# setup 进入伪图形化。

 

克隆机网卡问题处理:

克隆机执行ifconfig -a 发现网卡名为eth1.而配置文件为:ifcfg-eth0,处理方法有2种:

方法1:网卡名eth1保存不变:

修改配置文件名为eth1.

修改配置文件DEVICE=eth1

删除uuidhwaddr.

最后修改ip,重启网络服务。

方法2:让网卡名变成为eth0

 配置文件名不变。

删除uuidhwaddr.

ip修改一下

执行:  >  /etc/udev/rules.d/70-persitent-net.rules

最后reboot