Linux折腾记

  1. <big>Ubuntu: Stat / Stop / Restart Iptables Firewall Service</big>

    a) ufw command – This command is used for managing a Linux firewall and aims to provide an easy to use interface for the user.
    b) iptables command – This command is used to set up, maintain, and inspect the tables of IPv4 packet filter rules in the Linux kernel.

    Find status of firewall
    Login as root user either by opening the Terminal or login over the ssh based session. Type the following command:
    $ sudo ufw status
    Sample outputs:
    Status: inactive

    Ubuntu stop iptables service command
    Type the following command to unloads firewall and disables firewall on boot:
    $ sudo ufw disable

    Ubuntu start iptables service command
    Type the following command to reloads firewall and enables firewall on boot:
    $ sudo ufw enable

    Ubuntu reload / restart iptables service command
    Type the following command to reloads firewall:
    $ sudo ufw reload

    Alternative method to enable/disable firewall on Ubuntu and other Linux distros
    If you are not using ufw command and/or ufw is not installed, try the following generic methods:
    Get IPv4 iptables status
    $ sudo iptables -L -n -v

    Get IPv6 ip6tables status
    $ sudo ip6tables -L -n -v

    Save IPv4 iptables firewall
    Use the iptables-save command to save current firewall rules:
    $ sudo iptables-save > $HOME/firewall.txt

    Save IPv6 ip6tables firewall
    $ sudo ip6tables-save > $HOME/firewall-6.txt

    Restore IPv4 iptables firewall
    Use the iptables-restore command to restore firewall rules:
    $ sudo iptables-restore < $HOME/firewall.txt

    Restore IPv6 ip6tables firewall
    $ sudo ip6tables-restore < $HOME/firewall-6.txt

    Putting it all together
    To stop Ipv4 based iptables firewall, enter:

sudo iptables-save > $HOME/firewall.txt
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
To stop Ipv6 based iptables firewall, enter:
sudo ip6tables-save > $HOME/firewall-6.txt
sudo ip6tables -X
sudo ip6tables -t mangle -F
sudo ip6tables -t mangle -X
sudo ip6tables -P INPUT ACCEPT
sudo ip6tables -P FORWARD ACCEPT
sudo ip6tables -P OUTPUT ACCEPT
Where,
- **-F** : Flush the selected chain (all the chains in the table if none is given). This is equivalent to deleting all the rules one by one.
- **-X** : Delete the optional user-defined chain specified. There must be no references to the chain. If there are, you must delete or replace the referring rules before the chain can be deleted.
- **-P chainNameHere ACCEPT** : Set the policy for the chain to the given target.
- **-L** : List rules.
- **-v** : Verbose output.
- **-n** : Numeric output. IP addresses and port numbers will be printed in numeric format.

参考:https://www.cyberciti.biz/faq/ubuntu-start-stop-iptables-service/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 防火墙的概念iptables的简介iptables命令网络防火墙NATfirewalld服务 一、防火墙的概念 (...
    哈喽别样阅读 2,004评论 0 1
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 11,562评论 0 23
  • 开学我就大三了 她们都说我没长大 对啊我一直18岁但是这句话的背后却是我幼稚 不懂事我知道自己想事简单 做事不顾虑...
    alegre贺嘎哈阅读 278评论 0 0
  • 柒风著 可惜我活成了这个样子? 我不知道该如何描述现在的心情, 自己好像变得自私了。 那条人工河里的鱼很自在,柳枝...
    柒风有条白衬衫阅读 253评论 0 1
  • 一周二次 一次二时 一时八刀 我终于可以说自己是在纽约活过的人 没有丝毫经济头脑的我只有半年学习经济的经历,住在离...
    ZeroworldC阅读 368评论 0 1

友情链接更多精彩内容