ubuntu中防火墙iptables配置
特别说明:此文章完全转载于https://www.cnblogs.com/EasonJim/p/6851007.html
1.查看系统是否安装防火墙
root@localhost:/usr# which iptables
/sbin/iptables
root@localhost:/usr# whereis iptables
iptables: /sbin/iptables /etc/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz
如果是这样的信息,那么表明iptables就是安装了的。
如果没有安装,那么使用sudo apt-get install iptables 安装。
2.查看防火墙的配置信息
配置好了的,是这个样子。
root@localhost:/usr# sudo iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt: 22
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
ACCEPT icmp -- anywhere anywhere limit: avg 100/sec burst 100
ACCEPT icmp -- anywhere anywhere limit: avg 1/sec burst 10
syn-flood tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain syn-flood (1 references)
target prot opt source destination
RETURN tcp -- anywhere anywhere limit: avg 3/sec burst 6
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
3.新建规则文件
mkdir /etc/iptables #先新建目录,本身无此目录
vim /etc/iptables/rules.v4
/etc/iptables/rules.v4 中的内容是
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:syn-flood - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT
-A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN
-A syn-flood -j REJECT --reject-with icmp-port-unreachable
COMMIT
4.使防火墙生效
iptables-restore < /etc/iptables/rules.v4
5.创建文件,添加以下内容,使防火墙开机启动
vim /etc/network/if-pre-up.d/iptables
#!/bin/bash
iptables-restore < /etc/iptables/rules.v4
6.添加执行权限
chmod +x /etc/network/if-pre-up.d/iptables
7.查看规则是否生效
iptables -L -n
Ubuntu中没有直接停止关闭iptables的命令,像service iptables stop这类命令,是centos才有的。关闭的话,可以暂时开放所有端口作为替代方案
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
作者:yangyangrenren
链接:https://www.jianshu.com/p/6fe337cedbcb
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
ubuntu中防火墙iptables配置的更多相关文章
- ubuntu 19.10 中防火墙iptables配置
$sudo which iptables /usr/sbin/iptables说明有安装 如果没有安装,那么使用sudo apt-get install iptables 安装. 刚装机,是这个样 ...
- Ubuntu中保存iptables防火墙规则
Ubuntu中保存iptables防火墙规则的例子 打开防火墙 ufw disableufw statusufw enable ufw allow 22/tcp ufw reload iptables ...
- Ubuntu中使用iptables
(一) 设置开机启动iptables # sysv-rc-conf --level 2345 iptables on (二) iptables的基本命令 1. 列出当前iptables的策略和规则 # ...
- Ubuntu中安装和配置 Java JDK,并卸载自带OpenJDK(以Ubuntu 14.04为例)
1.下载jdk-7u67-linux-x64.tar.gz 2.用ftp客户端工具filezilla上传到ubuntu的合适文件夹.如果如果不能上传到指定文件夹可能是文件夹权限不足,修改文件夹可执行权 ...
- 在ubuntu中安装与配置zsh与oh-my-zsh
先补充点东西 1.ubuntu中默认安装了那些shell jiang@Linux:~$ cat /etc/shells # /etc/shells: valid login shells/bin/sh ...
- Linux的防火墙iptables配置示例
注:内容来自网络 一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:ser ...
- ubuntu 中DNAT SNAT配置实验.
1. 目的 图1 如图1所示,有A,B两台计算机,其中A配置成普通PC,B是网关.实现由A向一个不存在的IP 发起tcp连接,并能向这个不存在的ip发送数据. 同时响应这个tcp连接的是B中 ...
- Linux防火墙iptables配置开放某个端口
开放某个端口 查看防火墙规则命令: iptables -L -n 添加端口 1.编辑iptables文件 vim /etc/sysconfig/iptables 2.添加开放端口配置 -A INPUT ...
- ubuntu中为hive配置远程MYSQL database
一.安装mysql $ sudo apt-get install mysql-server 启动守护进程 $ sudo service mysql start 二.配置mysql服务与连接器 1.安装 ...
随机推荐
- MAMP PRO 在osx 10.10 错误处理
新更新的osx10.10之后,启动MAMP会发现Apache无法启动, 处理如下: 1.cd /Applications/MAMP/Library/bin 2.mv envvars _envvars ...
- 【转载】 C#中PadRight函数以特定字符在字符串结尾补足位数
在C#开发过程中字符串String类处理过程中,有时字符串长度不够时,需要在右侧侧指定特定的字符来补足字符串长度,此时可以使用String类下的PadRight方法对字符串结尾按特定的字符补足位数.M ...
- Axios使用拦截器全局处理请求重试
Axios拦截器 Axios提供了拦截器的接口,让我们能够全局处理请求和响应.Axios拦截器会在Promise的then和catch调用前拦截到. 请求拦截示例 axios.interceptors ...
- 阿里P7详细解答JVM性能调优之监控工具
javap 和 javac javac -verbose 类名.java java -verbose 类名 javap -c 类名 javap -verbose 类名 JAVAP -HELP 用法: ...
- RT-Thread--线程间同步
线程间同步 一个线程从传感器中接收数据并且将数据写到共享内存中,同时另一个线程周期性的从共享内存中读取数据并发送去显示,下图描述了两个线程间的数据传递: 如果对共享内存的访问不是排他性的,那么各个线程 ...
- websocket搭建的聊天室
在前后端数据交互的时候我们经常使用的是ajax,用的是传统的http协议,而http协议有个致命的缺点,就是请求一结束,连接就断开了, 我们为了保持这个链接的,通常会使用cookie,而自从h5出现w ...
- jFinal的小知识点总结
sql批处理 // 批处理sql List<String> sqlList = new ArrayList<String>(); sqlList.add("delet ...
- 再战css
1.盒模型的属性: 1.padding .box{ width: 200px; height: 200px; background-color: red; /*顺时针 上右下左*/ padding: ...
- P2921 [USACO08DEC]在农场万圣节[SCC缩点]
题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵 ...
- centOS7 下 安装mysql8.x
第一部分 CentOS7安装mysql1.1 安装前清理工作:1.1.1 清理原有的mysql数据库:使用以下命令查找出安装的mysql软件包和依赖包: rpm -pa | grep mysql 显示 ...