10.11 Linux网络相关10.12 firewalld和netfilter10.1310.14

本文涉及的产品
云防火墙,500元 1000GB
简介:

扩展(selinux了解即可):

1. selinux教程  

http://os.51cto.com/art/201209/355490.htm

2. selinux pdf电子书  

http://pan.baidu.com/s/1jGGdExK

SELinux中文.pdf

10.11 Linux网络相关

1. 安装ifconfig命令(centos7默认没安装):

[root@hao-01 ~]# yum install -y net-tools

2. 网卡当掉了,查看网卡ip:

[root@hao-01 ~]# ifconfig -a

3. 关闭指定网卡并且启动网卡ifdown 网卡名称 && ifup 网卡名称

(更改网卡配置,只针对更改网卡重启,就用关闭重启命令!千万不要随意当掉网卡!)

[root@hao-01 ~]# ifdown ens33 && ifup ens33

4. 设置虚拟网卡(拷贝网卡配置文件,并重命名):

cp /etc/sysconfig/network-scripts/原网卡 虚拟网卡

[root@hao-01 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33\:0

5. 编辑虚拟网卡

[root@hao-01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33\:0

网卡名称添加 :0  :  NAME=ens33:0

网卡名称添加 :0  : DEVICE=ens33:0

更改设定新的ip    : IPADDR=192.168.223.158

删除          : 网关DNS

clipboard.png

6. 关闭启动网卡(作用于重启这个网卡服务):

[root@hao-01 ~]# ifdown ens33 && ifup ens33

clipboard.png

7. 查看虚拟网卡(ens33:0):

[root@hao-01 ~]# ifconfig

clipboard.png

8. Windows系统,ping下虚拟网卡ip,查看是否ping通 ?

clipboard.png

9. 查看网卡是否连接(网线是否连接):mii-tool 网卡名

[root@hao-01 ~]# mii-tool ens33

连接: link ok   没有连接: no  link

clipboard.png

10. 查看网卡是否连接(网线是否连接):ethtool ens33

[root@hao-01 ~]# ethtool ens33

连接: Link detected: yes   没有连接:Link detected: no

11. 更改主机名(重启更新):hostnamectl set-hostname 新主机名

[root@hao-01 ~]# hostnamectl set-hostname hao-001

12. 查看主机名hostname

[root@hao-01 ~]# hostname

clipboard.png

13. 查看主机名配置文件

[root@hao-001 ~]# cat /etc/hostname

clipboard.png

14. 查看DNS配置文件(更改dns需要在网卡配置文件里修改!) 

[root@hao-001 ~]# cat /etc/resolv.conf

clipboard.png

15. 查看/etc/hosts文件(设定域名,解析到指定ip):

[root@hao-001 ~]# cat /etc/hosts

16. 编辑/etc/hosts文件,设定域名 解析到指定ip地址

[root@hao-001 ~]# vi /etc/hosts

添加:指定到的ip地址  网址  域名

192.168.223.157 www.qq123.com www.baidu.com

clipboard.png

17. ping下,设定的域名已解析到指定ip

[root@hao-001 ~]# ping www.qq123.com

clipboard.png

10.12 firewalld和netfilter

selinux(关闭这个防火墙)

1. 临时关闭selinux(防火墙) : setenforce 0

[root@hao-001 ~]# setenforce 0

2. 永久关闭selinux(防火墙),编辑...config配置文件 :

(好多服务,受限于selinux,关闭selinux也不会有太大的安全问题)

[root@hao-001 ~]# vi /etc/selinux/config

更改:SELINUX=disabled

clipboard.png

firewalld(关闭centos7默认防火墙)

(firewalld默认是centos7的防火墙,可以关闭掉这个,用centos6上的防火墙netfilter

3. 禁止开机启动firewalld服务(centos7默认防火墙) :

[root@hao-001 ~]# systemctl disable firewalld

clipboard.png

4. 关掉(停止)firewalld服务(centos7默认防火墙) :

[root@hao-001 ~]# systemctl stop firewalld

netfilter(开启centos6默认防火墙)

5. 安装netfilter服务(centos6或centos5默认防火墙) :

注意:(iptablesnetfiltel防火墙的工具)

[root@hao-001 ~]# yum install -y iptables-services

6. 启用iptables服务 :

[root@hao-001 ~]# systemctl enable iptables

7. 开启iptables服务 :

[root@hao-001 ~]# systemctl start iptables

8. 查看iptables默认规则 :

[root@hao-001 ~]# iptables -nvL

clipboard.png

10.13 netfilter5表5链介绍

Linux防火墙-netfilter

• netfilter的5个表

• filter表用于过滤包,最常用的表,有INPUT、FORWARD、OUTPUT三个链

• nat表用于网络地址转换,有PREROUTING、OUTPUT、POSTROUTING三个链

• managle表用于给数据包做标记,几乎用不到

• raw表可以实现不追踪某些数据包,阿铭从来不用

• security表在Centos6中并没有,用于强制访问控制(MAC)的网络规则,阿铭老师没用过

• 参考文章 http://www.cnblogs.com/metoy/p/4320813.html

• 数据包流向与netfilter的5个链

• PREROUTING:数据包进入路由表之前

• INPUT:通过路由表后目的地为本机

• FORWARD:通过路由表后,目的地不为本机

• OUTPUT:由本机产生,向外发出

• POSTROUTING:发送到网卡接口之前

clipboard.png

10.14 iptables语

1. 查看iptables默认规则配置文件:

[root@hao-001 ~]# cat /etc/sysconfig/iptables

2. 查看iptables默认规则:

[root@hao-001 ~]# iptables -nvL

3. 保存iptables规则(当前规则,保存到配置文件):

[root@hao-001 ~]# service iptables save

4. 清空iptables规则:

[root@hao-001 ~]# iptables -F

5. 重启iptables规则

[root@hao-001 ~]# service iptables restart

7. 指定表:

[root@hao-001 ~]# iptables -t nat -nvL

[root@hao-001 ~]# iptables -t filter -nvL

8. 把表的计数器清零:

[root@hao-001 ~]# iptables -nvL

-A 增加一条规则,添加在最后

9. 增加规则增加最后面

iptables -A(增加一条规则) INPUT(链) -s 来源ip -p tcp(协议)  --sport 来源端口 -d 目标ip --dport 目标端口 -j DROP(扔掉)

[root@hao-001 ~]# iptables -A INPUT -s 192.168.223.1 -p tcp --sport 1234 -d 192.168.223.128 --dport 80 -j DROP

[root@hao-001 ~]# iptables -nvL

clipboard.png

注意:不加-t,默认filter

-A INPUT  增加一条规则(添加到最后INPUT

-I INPUT     插入一条规则(添加到最前)  INPUT

-D INPUT   删除一条规则  INPUT

-s                指定来源ip

-p               指定协议为tcp  

--sport       指定来源端口

-d               指定目标ip

--dport       指定目标端口

-i                 指定网卡

-t nat          指定  nat

不加-t :       默认指定filter

-j DROP     扔掉

10. 删掉规则

iptables -D(删除一条规则) INPUT(链) -s 来源ip -p tcp(协议) --sport 来源端口 -d 目标ip --dport 目标端口 -j DROP(扔掉)

[root@hao-001 ~]# iptables -D INPUT -s 192.168.223.1 -p tcp --sport 1234 -d 192.168.223.128 --dport 80 -j DROP

-I 插入一条规则,添加在最前

(排在最前的规则,优先过滤前面的,再过滤下面的规则)

11. 插入规则添加最前面

iptables -I(插入一条规则) INPUT(链) -p tcp(协议) --dport 目标端口 -j DROP(扔掉)

[root@hao-001 ~]# iptables -I INPUT -p tcp --dport 80 -j DROP

[root@hao-001 ~]# iptables -nvL

clipboard.png

12. 插入规则添加最前面并指定网卡

-i 指定网卡

iptables -I(插入一条规则) INPUT(链)  -s 来源IP/24 -i 网卡名称 -j ACCEPT(扔掉)

[root@hao-001 ~]# iptables -I INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT

13. 删掉 设定的规则(自己记得规则怎么写的,要不没法指定删除哦):

[root@hao-001 ~]# iptables -D INPUT -p tcp --dport 80 -j DROP

删除规则?简单方便!!!

14. 打印出规则序列号编号:

[root@hao-001 ~]# iptables -nvL --line-number

clipboard.png

15. 删除指定规则:iptables -D INPUT 规则序列号编号

[root@hao-001 ~]# iptables -D INPUT 2

•更改默认规则(不常用慎用):iptables -P INPUT DROP

•恢复默认规则:iptables -P OUTPUT ACCEPT










本文转自 主内安详 51CTO博客,原文链接:http://blog.51cto.com/zhuneianxiang/2064621,如需转载请自行联系原作者
目录
相关文章
|
4月前
|
安全 网络协议 Linux
Linux网络应用层协议展示:HTTP与HTTPS
此外,必须注意,从HTTP迁移到HTTPS是一项重要且必要的任务,因为这不仅关乎用户信息的安全,也有利于你的网站评级和粉丝的信心。在网络世界中,信息的安全就是一切,选择HTTPS,让您的网站更加安全,使您的用户满意,也使您感到满意。
124 18
|
4月前
|
Linux 数据安全/隐私保护
使用Linux命令行接入无线网络Wi-Fi的示例。
现在,你已经使用命令行成功地连接到 Wi-Fi 网络了。这两个示例涵盖了用 `nmcli` 和 `wpa_supplicant` 连接无线网络的常见场景,让你能够不依赖图形化界面来完成这个任务。在日常使用中熟练掌握这些基本操作能增强你对 Linux 系统的理解,帮助你更有效地处理各种问题。
166 12
|
4月前
|
安全 Ubuntu Linux
Nipper 3.8.0 for Windows & Linux - 网络设备漏洞评估
Nipper 3.8.0 for Windows & Linux - 网络设备漏洞评估
138 0
Nipper 3.8.0 for Windows & Linux - 网络设备漏洞评估
|
6月前
|
Ubuntu Linux
Linux系统管理:服务器时间与网络时间同步技巧。
以上就是在Linux服务器上设置时间同步的方式。然而,要正确运用这些知识,需要理解其背后的工作原理:服务器根据网络中的其他机器的时间进行校对,逐步地精确自己的系统时间,就像一只犹豫不决的啮齿动物,通过观察其他啮齿动物的行为,逐渐确定自己的行为逻辑,既简单,又有趣。最后希望这个过程既能给你带来乐趣,也能提高你作为系统管理员的专业素养。
1015 20
|
6月前
|
JSON 运维 Ubuntu
Linux下如何使用Curl进行网络请求
希望这篇文章能帮助您在Linux下更好地使用Curl进行网络请求。如有疑问,请随时提问!
307 10
|
8月前
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
1071 28
|
8月前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
294 11
|
网络协议 Linux 网络安全
百度搜索:蓝易云【Linux 防火墙配置(iptables和firewalld)详细教程。】
以上只是一些常见的iptables和firewalld命令示例,你可以根据自己的需求进行修改和扩展。请注意,在配置防火墙时务必小心,确保不会阻塞你所需要的合法流量,并确保保存和加载配置以使其永久生效。另外,建议在配置防火墙之前备份现有的防火墙规则以防止意外情况发生。
646 2
|
存储 XML 安全
Linux防火墙firewalld安全设置(下)
Linux防火墙firewalld安全设置
Linux防火墙firewalld安全设置(下)

热门文章

最新文章