关于Linux6/7系关闭selinux和防火墙,配置网络IP地址

本文介绍了Linux 6/7系关闭SElinux和防火墙、配置网络IP地址的方法。包括查看和关闭SElinux状态、关闭其自启动,不同版本关闭防火墙的指令,以及查看网卡、编辑文件添加网络信息、重启网络和测试连通性等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于Linux6/7系关闭SElinux和防火墙,配置网络IP地址

关闭SElinux

什么是SElinux?
SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。
笼统来说,就是我的电脑我做主,默认关闭。

1.getenforce命令查看SELinux状态,显示enforcing表示SElinux未关闭。

[root@localhost ~]# getenforce
Enforcing

2.setenforce 0命令关闭SELinux,显示permissive表示SElinux关闭。

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive

3.关闭SELinux自启动,编辑vim /etc/selinux/config,将SELINUX=enforcing修改成SELINUX=disabled,保存退出wq!

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

4 getenforce命令查看SELinux状态,显示Disabled表示SElinux关闭。

[root@localhost ~]# getenforce
Disabled

关闭防火墙

如果不去关闭防火墙,对外部链接用限制,同样,我的电脑我做主
6系、7系关闭指令不同
1.查看防火墙状态

[root@localhost ~]# service iptables status \\6[root@localhost ~]# systemctl status firewalld \\7

2.关闭防火墙

[root@localhost ~]# service iptables stop \\6[root@localhost ~]# systemctl stop firewalld \\7

3.关闭防火墙自启

[root@localhost ~]# chkconfig iptables off \\6[root@localhost ~]# systemctl disable firewalld \\7

配置网络

1.查看网卡

[root@localhost ~]# ifconfig   ///显示内容为网卡信息

2.打开cd /etc/sysconfig/network_scripts,查看文件ls

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls   

3.编辑vim (根据自己的网卡名来),添加IPADDR=IP地址,NETMASK=子网掩码,GATEWAY=网关,将ONBOOT=no改为yes,BOOTPROTO=dhcp改为static,其他内容不用改,保存退出wq!

[root@localhost network-scripts]# vim ifcfg-ens192
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.X.XXX"
NETMASK="255.255.255.0"
GATEWAY="192.168.X.1"
DNS1="8.8.8.8"

4.重启网络service network restart

[root@localhost network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]

5.ping网关是否连通

[root@localhost network-scripts]# ping 192.168.X.1
PING 192.168.X.1 (192.168.X.1) 56(84) bytes of data.
64 bytes from 192.168.X.1: icmp_seq=1 ttl=255 time=1.16 ms
64 bytes from 192.168.X.1: icmp_seq=2 ttl=255 time=2.11 ms
64 bytes from 192.168.X.1: icmp_seq=3 ttl=255 time=1.18 ms
64 bytes from 192.168.X.1: icmp_seq=4 ttl=255 time=1.31 ms

本身也是在学习过程中,记下一笔,希望能有所帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值