特别说明:此文章完全转载于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

还可以参考https://blog.csdn.net/langsim/article/details/42644451

作者:yangyangrenren
链接:https://www.jianshu.com/p/6fe337cedbcb
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

ubuntu中防火墙iptables配置的更多相关文章

  1. ubuntu 19.10 中防火墙iptables配置

    $sudo which iptables   /usr/sbin/iptables说明有安装 如果没有安装,那么使用sudo apt-get install iptables 安装. 刚装机,是这个样 ...

  2. Ubuntu中保存iptables防火墙规则

    Ubuntu中保存iptables防火墙规则的例子 打开防火墙 ufw disableufw statusufw enable ufw allow 22/tcp ufw reload iptables ...

  3. Ubuntu中使用iptables

    (一) 设置开机启动iptables # sysv-rc-conf --level 2345 iptables on (二) iptables的基本命令 1. 列出当前iptables的策略和规则 # ...

  4. Ubuntu中安装和配置 Java JDK,并卸载自带OpenJDK(以Ubuntu 14.04为例)

    1.下载jdk-7u67-linux-x64.tar.gz 2.用ftp客户端工具filezilla上传到ubuntu的合适文件夹.如果如果不能上传到指定文件夹可能是文件夹权限不足,修改文件夹可执行权 ...

  5. 在ubuntu中安装与配置zsh与oh-my-zsh

    先补充点东西 1.ubuntu中默认安装了那些shell jiang@Linux:~$ cat /etc/shells # /etc/shells: valid login shells/bin/sh ...

  6. Linux的防火墙iptables配置示例

    注:内容来自网络 一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:ser ...

  7. ubuntu 中DNAT SNAT配置实验.

    1.      目的 图1 如图1所示,有A,B两台计算机,其中A配置成普通PC,B是网关.实现由A向一个不存在的IP 发起tcp连接,并能向这个不存在的ip发送数据. 同时响应这个tcp连接的是B中 ...

  8. Linux防火墙iptables配置开放某个端口

    开放某个端口 查看防火墙规则命令: iptables -L -n 添加端口 1.编辑iptables文件 vim /etc/sysconfig/iptables 2.添加开放端口配置 -A INPUT ...

  9. ubuntu中为hive配置远程MYSQL database

    一.安装mysql $ sudo apt-get install mysql-server 启动守护进程 $ sudo service mysql start 二.配置mysql服务与连接器 1.安装 ...

随机推荐

  1. linux的scp命令可以在linux服务器之间复制文件和目录

    scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器 ...

  2. SQL链接服务器查询-OPENQUERY的使用

    OpenQuery: 用途:与其他Server交互的技术,通过它能够直接访问其他数据库资源.可以跨平台连接,包括Oracle   --创建链接服务器 exec sp_addlinkedserver ' ...

  3. NRF52832 Mesh调试,使其同时支持串口打印和RTT打印

    查看开发环境里面,是否有这个文件,如果没有你的话,则添加文件. 然后要在sdk_config.h中添加使能 然后打开刚才添加的文件retarget.c,主意里面这些地方 这里它进行判断,要么使用RTT ...

  4. PHP原生EXCEL导出带样式无插件无乱码实现

    PHP原生EXCEL导出 经测试 带样式 无插件 无乱码,不需要引入任何插件,不需要修改任何编码 (使用时只需要修改引入php数据库配置文件.修改thead tbody中的数据即可.根据自己的需要去接 ...

  5. ios 日常开发常用宏定义

      #pragma mark - 字体.颜色相关 #define kFONT_SIZE(f) [UIFont systemFontOfSize:(f)] #define kFONT_BOLD_SIZE ...

  6. Android 在同一台设备上安装多个同一项目的apk

    如果设备上已经安装了一个apk,再次安装这个apk就会提示覆盖前面的应用 解决办法: 方法一:手动改包名 不好改,改了几次都不成功(可能是代码在svn管理的原因,改完后文件夹里的代码就没了),确实不实 ...

  7. 【SpringMVC】RESTful支持

    一.概述 1.1 什么是RESTful 1.2 URL的RESTful实现 二.演示 2.1 需求 2.2 第一步更改DispatcherServlet配置 2.3 第二步参数通过url传递 2.4 ...

  8. Shodan全世界在线设备搜索引擎

    reproduction from https://danielmiessler.com/study/shodan/ What is Shodan? Shodan is a search engine ...

  9. JSON 的简介与使用

    一.什么是JSON? JSON(javascript object notation)全称是 javascript 对象表示法,是一种数据交换的文本格式,用于读取结构化数据,提出目的是取代繁琐笨重的 ...

  10. tinylogin-1.4

    tinylogin-1.4是一个开发嵌入式的文件系统很好的一个工具