- Understanding Firewalls
- Concept
- Role
- Firewall category on Linux
- Packet filtering mechanism NetFilter
- Program Control mechanism TCP Wrappers
- General network Cabling
- Ability to use limits
- TCP Wrappers Program Control
- Concept:
In short, TCP wrappers is managed through the two files of /etc/hosts.allow and /etc/hosts.deny , but not all software is available.
- Supported Services
- Super Daemon (XINETD) Managed Services
Chkconfig--list the XINETD based services under Display content:
- Services that support libwrap.so modules
Because the service that supports TCP wrappers must contain libwrap, this dynamic library can be observed by LDD:
LDD ' which sshd ' | grep libwrap
libwrap.so.0 =/lib/libwrap.so.0 (0x00145000)
- /etc/hosts. How to set {Allow|deny}
- Grammatical structure
<service (program_name) >:<IP,domain,hostname>
such as rsync:192.168.1.0/255.255.255.0
- Rule priority order
- /etc/hosts.allow
- /etc/hosts.deny
- If none of the above is met, release
- Packet filtering software: iptables
Kernel2.4 and more than 2.6 use iptables this mechanism, PS:UNAME-R view core version
- Comparison and analysis order
Rule1
Rule2
Policy Preset Packet action
- Table and Chain
- Table (Tables): Filter (Filter), Nat (), mangle ()
- Filter:input, OUTPUT, FORWARD
- NAT: Prerouting, Postrouting, OUTPUT
- mangle: multiple
- Chain (chain)
- INPUT: A rule that is primarily responsible for making packets that you want to enter into a Linux host
- OUTPUT
- FORWARD
- Grammatical structure
- View of rules
iptables [-T tables] [-l] [-NV]
- -T
- -L: List Rule contents of table
- -N
- -V
- Iptables Content Composition
Target Prot opt source destination
- Target
- Prot
- Opt
- Source
- Destination
- Purge of rules
iptables [-t tables] [-FXZ]
- -F: Clears all existing rules (not permanent changes unless the configuration file is written)
- -X: Kill all Custom
- -Z: Zeroing all chain statistics
- Defining a preset packet action policy
Policy: When your packet is not within the set rules, the packet is passed or not, whichever is the policy setting (that is, the last rule)
iptables [-T tables]-p [chain] [Accept,drop]
- ACCEPT
- DROP
- The comparison setting of the packet
Usage: iptables [-ai chain] [-io network Interface] [-P protocol] [-s source IP] [-d Destination IP]-j [accept| drop| Reject| LOG]
Example:
Iptables-i input-i eth0-d--dport 22-j DROP #禁止远程主机SSH连接
If no item is specified, the item is fully accepted
- -A: New rule added
- -I: Inserting a new rule
- -I: Ingress network interface for use with input chain
- -O: Egress network interface
- -P: Set this rule to apply that kind of protocol, mainly Tcp,udp,icmp,all
- -S
- -D
- -j
- -P [TCP|UDP]--sport
- -P [TCP|UDP]--dport
- iptables Plug-in module
Usage:-M [State|mac]--state |--mac
Example:
iptables-a input-m State--state related -j ACCEPT
Iptables-i input-m mac--mac-source aa:bb:cc:dd:ee:ff
- --state: Status of some packets
INVALID
established
new< br>related
- --mac: Set rules based on MAC address
- ICMP packet rule: for response ping
Usage:-m ICMP--icmp-type
- icmp-type corresponding to
0 |
3 |
4 |
8 |
11 |
12 |
echo Reply |
not up |
source quench |
echo request |
ttl=0 |
Bad package |
- Disable remote host ping package
Iptables-i input-p ICMP--icmp-type 8-j DROP & nbsp #不接受echo Request
or
Iptables-i output-p ICMP--icmp-type 0-j DROP #不发出echo reply
li>
- Write Firewall rule configuration file
Configuration file /etc/sysconfig/iptables
/etc/init.d/iptables Save #将防火墙规则写入到/etc/sysconfig/iptables
#iptables: Saving firewall rules to/etc/sysconfig/iptables:[ OK ]
- IPV4 's core management function:/proc/sys/net/ipv4/*
Firewall Basics--TCP Wrappers and iptables two kinds of mechanisms