Linux firewall related configuration commands and operations (centos and ubuntu)

ubuntu and centos firewall configuration commands and operations

Everyone enters keywords such as [linux firewall] to search for related articles on the Internet, and sometimes the command cannot be used, not because their command is wrong, but because of the operating system version.
At present, the more common Linux systems are centos and ubuntu.
Stop talking nonsense, just open up

centos

At present, the most commonly used centos version is 7.x, here is 7.x to expand, and also talk about the difference with 6.x

  1. x version uses firewall by default, while 6.x version uses iptables by default

All installations are yum install, such as: yum install iptables-services

iptables firewall##

  1. Basic command
# View firewall status
service iptables status
# Stop firewall
service iptables stop
# Start firewall
service iptables start
# Restart firewall
service iptables restart
# Permanently turn off the firewall
chkconfig iptables off
# Restart after permanent shutdown
chkconfig iptables on

2. The operation of opening ports in iptables firewall state

# Open port 80
vim /etc/sysconfig/iptables
# Add the following code
- A INPUT -m state --state NEW -m tcp -p tcp --dport 80-j ACCEPT
Restart the firewall after saving and exiting

firewall firewall##

  1. Basic command
# View firewall service status(Active appears:active(running)Is the start state, Active:inactive(dead)Is stopped)
systemctl status firewalld
# View firewall status
firewall-cmd --state
# Open firewall.service
service firewalld start
# Restart firewall.service
service firewalld restart
# Close firewall.service
service firewalld stop
# View firewall rules
firewall-cmd --list-all
# Check if the port is open
firewall-cmd --query-port=8080/tcp
# Open port 80
firewall-cmd --permanent --add-port=80/tcp
# Remove port
firewall-cmd --permanent --remove-port=8080/tcp
# Restart the firewall (restart the firewall after modifying the configuration)
firewall-cmd --reload
# Parameter introduction
firewall-cmd is a tool for operating firewall provided by Linux
- - permanent means set to permanent
- - add-port identifies the added port
  1. Turn off firewall and turn off auto-start
# Stop firewall
systemctl stop firewalld.service
# Prohibit firewall startup
systemctl disable firewalld.service
  1. Set the firewall to start automatically
systemctl enable iptables.service

ubuntu

  1. Basic command
# installation
sudo apt-get install ufw
# View firewall version
sudo ufw version
# View firewall status
sudo ufw status
# Enable firewall
sudo ufw enable
# Allow external access to this machine by default
sudo ufw default allow
# Deny external access to the host by default
sudo ufw default deny
# Turn off the firewall
sudo ufw disable
# Permanently turn off the firewall
systemctl stop firewalld.service
  1. Port number opening and closing
# Allow external access to port 80
sudo ufw allow 80
# Deny external access to port 80
sudo ufw deny 80
  1. Allow a certain IP address to access all ports of the machine
sudo ufw allow from192.168.0.1

Recommended Posts

Linux firewall related configuration commands and operations (centos and ubuntu)
[Linux] ubuntu install configuration vsftpd and lock the directory
The difference between CentOS and Ubuntu in Linux system
Summary of linux (centos) project deployment phase related commands
Centos mysql installation and configuration
Know Linux and install CentOS
Centos7 installation and configuration prometheus
CentOS 7 installation and configuration PPTP
Ubuntu16.04 installation and simple configuration
CentOS installation and configuration cmake
Centos7.5 installation and configuration MongoDB4.0.4
CentOS 7 installation and configuration PPTP
Ubuntu16.04 install SVN and configuration
Ubuntu PostgreSQL installation and configuration
Centos7 installation and configuration of Jenkins
Common Linux operations (based on centos7)
CentOS 8 install Git and basic configuration
The difference between CentOS and Ubuntu
Ubuntu environment variables and ADB configuration
Centos7 hadoop cluster installation and configuration
CentOS7.2 and Nginx configuration virtual host
Ubuntu16.04 configuration OpenCV3.4.2 and basic use
Java-JDK installation and configuration under CentOS
CentOS 7 Tomcat service installation and configuration
Centos 7 RAID 5 detailed explanation and configuration
Ubuntu 19.1 installation and configuration Chinese environment
CentOS NTP server installation and configuration
Configuration and beautification after Ubuntu installation (1)
Nginx installation and configuration load (ubuntu12.04)
Ubuntu upgrade software and ubuntu upgrade system commands
Linux CentOS6 compile and install Pyt
Ubuntu configuration source and installation software
Centos7 mysql database installation and configuration
Linux basics (Ubuntu copy and paste)
A brief introduction to yum source configuration and nmcli commands under CentOS8
CentOS 7 system installation and configuration graphic tutorial
Linux development preparation-install VMware and run Ubuntu
Tomcat installation and configuration under CentOS 7 (Tomcat startup)
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
Linux kernel compilation and CentOS system installation
Installation and configuration of redis under centos7
Ubuntu install PHP and PHP Nginx configuration method
Centos7 hive stand-alone mode installation and configuration
Ubuntu 14.04 16.04 Linux nvidia driver download and installation
Linux install Docker and run Ubuntu system
DLNA/UPnP Server installation and configuration under Ubuntu 12.04
Linux CentOS regularly run script configuration method
Centos7 configuration host name and IP address
Linux (ubuntu 12.04)
Installation and configuration of JDK in CentOS 7 system
Debian and Ubuntu installation source configuration file description
Linux distribution: CentOS, Ubuntu, RedHat, Android, Tizen, MeeGo
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
Install and use Git and GitHub on Ubuntu Linux
CentOS7 and Docker configuration Chinese character set problem
CentOS 7 installation and configuration graphic tutorials under VMware10
Centos7.6 dual network card configuration and switching test
Install svn and configuration through yum under CentOS
Installation and configuration of rsync server under CentOS 6.5
Kaldi installation and configuration graphic tutorials under Ubuntu
Basic configuration and common software installation after ubuntu 18.04 installation