Linux网络相关、firewalld和netfilter 、netfilter5表5链介绍 、 iptables语法

发布时间:2024-05-07 点击:104
linux网络相关
ifdown ens33 关闭网卡&& ifup ens33 启动网卡 (&&一起执行)
应用场景:当想单独更改某个网卡的信息时,可使用此命令
设定虚拟网卡
cd /etc/sysconfig/network-scripts/ 进入网卡目录
cp ifcfg-ens33 ifcfg-ens33:0 拷贝网卡配置文件
vi !$编辑配文件
修改name :ens33:0
device :ens33 :0
ipaddr 更换ip
删除dns1 gateway
修改后关闭,开启网卡。
查看网卡是否连接(link ok表示连接)
[root@g_linux01 network-scripts]# mii-tool ens33 ens33: negotiated 1000baset-fd flow-control, link ok
如果mii-tool ens33不支持 也可用ethtool ens33
[root@g_linux01 network-scripts]# ethtool ens33 settings for ens33: supported ports: [ tp ] supported link modes: 10baset/half 10baset/full 100baset/half 100baset/full 1000baset/full supported pause frame use: no supports auto-negotiation: yes advertised link modes: 10baset/half 10baset/full 100baset/half 100baset/full 1000baset/full advertised pause frame use: no advertised auto-negotiation: yes speed: 1000mb/s duplex: full port: twisted pair phyad: 0 transceiver: internal auto-negotiation: on mdi-x: off (auto) supports wake-on: d wake-on: d current message level: 0x00000007 (7) drv probe link link detected: yes 更改主机名
hostnamectl set-hostname [主机名] (centos7的命令)
配置文件在/etc/hostname
dns配置文件
/etc/resolv.conf(可临时更改,想永久更改要在网卡配置文件中改)
etc/hosts 更改本机域名解析
以先出现的记录为主。 这个文件也是从上到下依次执行的,127.0.0.1是特例,本机ip优先级高
firewalld和netfilter
复习selinux
修改配置文件中selinux=disabled
getenforce 可查询selinux是否开启
可能返回结果有三种:enforcing、permissive和disabled。disabled 代表 selinux 被禁用,permissive 代表仅记录安全警告但不阻止可疑行为,enforcing 代表记录警告且阻止可疑行为。
firewalld
centos7 默认开启firewalld 关闭netfilter,netfilter 是centos6的防火墙。但7依然可以用
关闭firewalld 流程
systemctl disable firewalld 不开机启动 systemctl stop firewalld 在关掉
开启netfilter
先安装yum install -y iptables-services systemctl enable iptables 设为开机启动 systemctl start iptables 启动服务 netfilter5个表5个链介绍
filter,nat,mangle,raw,默认表是filter(没有指定表的时候就是filter表)。
filter:一般的过滤功能
nat:用于nat功能(端口映射,地址映射等)
mangle:用于对特定数据包的修改
raw:优先级最高,设置raw时一般是为了不再让iptables做数据包的链接跟踪处理,提高性能
数据报从进入系统,进行ip校验以后,首先经过第一个hook函数nf_ip_pre_routing进行处理; 然后就进入路由代码,其决定该数据报是需要转发还是发给本机的; 若该数据报是发被本机的,则该数据经过hook函数nf_ip_local_in处理以后然后传递给上层协议; 若该数据报应该被转发则它被nf_ip_forward处理; 经过转发的数据报经过最后一个hook函数nf_ip_post_routing处理以后,再传输到网络上。 本地产生的数据经过hook函数nf_ip_local_out 处理后,进行路由选择处理,然后经过nf_ip_post_routing处理后发送出去。 iptables语法
案例:http://blog.chinaunix.net/uid-9950859-id-98279.html
查看默认规则
[root@g_linux01 ~]# iptables -nvl chain input (policy accept 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 116k 28m accept all — * * 0.0.0.0/0 0.0.0.0/0 ctstate related,established 0 0 accept all — lo * 0.0.0.0/0 0.0.0.0/0 11342 963k input_direct all — * * 0.0.0.0/0 0.0.0.0/0 11342 963k input_zones_source all — * * 0.0.0.0/0 0.0.0.0/0 11342 963k input_zones all — * * 0.0.0.0/0 0.0.0.0/0 0 0 drop all — * * 0.0.0.0/0 0.0.0.0/0 ctstate invalid 11330 963k reject all — * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
重启规则service iptabales restart(重启后会加载配置文件中的规则)
保存规则service iptables save(修改后不保存,重启后会失效)
规则保存在 cat /etc/sysconfig/iptables(如果没有安装yum install iptables-services)
iptables -f 清空规则
iptables -t filter -nvl (指定显示哪个表的规则,不加-t 默认显示filter)
iptables -t nat -nvl
iptables -z 清空计数器
限制某ip登录
iptables -a input -s 192.168.188.1 -p tcp –sport 1234 -d 192.168.188.128 –dport 80 -j dorp/reject
-a 增加一条规则,针对input链(在最后插入规则) -s 来源 -p 指定协议tcp 或者udp –sport 端口1234 -d 目标ip –dport 目标端口 -j 具体操作 dorp 拒绝(数据包来了,看都不看直接扔掉) reject

网站打不开请尽快处理-虚拟主机/数据库问题
国内便宜云服务器租用
Commvault任命Callum Eade担任亚太及日本地区销售副总裁
免费的云服务器怎么样
两会催新基建迅速落地 数据中心建设将成最大赢家
可信云线上峰会丨《研发运营安全白皮书》详解研发运营安全那些事儿
正规的重庆双线服务器租用云主机
这个打开怎么老是提示一个不相干的页面