Iptables firewall and log system

Source: Internet
Author: User
Example 1), # iptables? AINPUT? Ptcp -- dport22? JLOG -- log-level5 -- log-prefix "IPTABLES:" -- log-level: log level is 5, -- log-prefix information is "IPTABLES:" for why log level is 5, possible IptablesAn example of using the firewall with the log system

1 ),#Iptables? A input? P tcp -- dport 22? J LOG -- log-level 5 -- log-prefix "IPTABLES :"

-- Log-level: the log level is 5, and the prefix information of -- log-prefix is "IPTABLES :"

For more information about why the log level is 5, see # man syslog's 8 levels. here, the log level must correspond to the log level of iptables -- log-level.

2) edit the/etc/syslog. conf configuration file.

Added: kern. = notice/var/log/firewall. log option (kern indicates kernel information;. =Indicates match; notice indicates message)

[Root @ localhost root] #Iptables-a input-p tcp-d192.168.0.253 -- dport 22-j LOG -- log-level 5 -- log-prefix "IPTABLES :"
[Root @ localhost root] #Vi/etc/syslog. conf
[Root @ localhost root] #Cat/etc/syslog. conf | grepnotice
Kern. = notice/var/log/firewall. log
[Root @ localhost root] #Man syslog | grep''
# Include
# Include
# Include
DEFAULT_MESSAGE_LOGLEVEL-1 (6) unless the line starts with where
Ventional meaning of the loglevel is defined in
# DefineKERN_EMERG ""/* system isunusable */
# DefineKERN_ALERT ""/* actIon must be takenimmediately */
# DefineKERN_CRIT ""/* criticalconditions */
# DefineKERN_ERR ""/* errorconditions */
# Define KERN_WARNING ""/* warningconditions */
# DefineKERN_NOTICE ""/* normal but significantcondition */
# DefineKERN_INFO ""/* informational */
# DefineKERN_DEBUG ""/* debug-levelmessages */
[Root @ localhost root] #Service syslogrestart
Shutting down kernellogger: [OK]
Shutting down systemlogger: [OK]
Starting systemlogger: [OK]
Starting kernellogger: [OK]
[Root @ localhost root] #Iptables-a input-p tcp-d192.168.0.253 -- dport 22-j ACCEPT
[Root @ localhost root] #Iptables-L-n -- line-numbers
Chain INPUT (policy DROP)
Num target prot optsource destination
1 ACCEPT tcp -- 0.0.0.0/0 192.168.0.253 tcp dpt: 22
2 ACCEPT all -- 127.0.0.1 127.0.0.1
3 ACCEPT udp -- 0.0.0.0/0 192.168.0.253 udp spt: 53 stateESTABLISHED
4 LOG tcp -- 0.0.0.0/0 192.168.0.253 tcp dpt: 22 LOG flags 0 level 5 prefix 'iptables :'
5 ACCEPT tcp -- 0.0.0.0/0 192.168.0.253 tcpdpt: 22

Chain FORWARD (policy DROP)
Num target prot optsource destination

Chain OUTPUT (policy DROP)
Num target prot opt source destination
1 ACCEPT tcp -- 192.168.0.253 0.0.0.0/0 tcpspt: 22 state ESTABLISHED
2 ACCEPT all -- 127.0.0.1 127.0.0.1
3 ACCEPT udp -- 192.168.0.253 0.0.0.0/0 udpdpt: 53
[Root @ localhost root] #Iptables-d input 1
[Root @ localhost root] #Iptables-L-n -- line-numbersReview iptables records andSequenceLink ~!
Chain INPUT (policy DROP)
Num target prot optsource destination
1 ACCEPT all -- 127.0.0.1 127.0.0.1
2 ACCEPT udp -- 0.0.0.0/0 192.168.0.253 udp spt: 53 stateESTABLISHED
3 LOG tcp -- 0.0.0.0/0 192.168.0.253 tcp dpt: 22 LOG flags 0 level 5 prefix 'iptables :'
4 ACCEPT tcp -- 0.0.0.0/0 192.168.0.253 tcp dpt: 22

Chain FORWARD (policy DROP)
Num target prot optsource destination

Chain OUTPUT (policy DROP)
Num target prot optsource destination
1 ACCEPT tcp -- 192.168.0.253 0.0.0.0/0 tcpspt: 22 state ESTABLISHED
2 ACCEPT all -- 127.0.0.1 127.0.0.1
3 ACCEPT udp -- 192.168.0.253 0.0.0.0/0 udpdpt: 53
[Root @ localhost root] #Tail/var/log/firewall. log
Aug 6 02:44:14 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 128TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18358 df proto = tcp spt = 1812 DPT = 22 WINDOW = 65483 RES = 0x00 ack psh urgp = 0
Aug 6 02:44:14 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 40TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18363 df proto = tcp spt = 1812 DPT = 22 WINDOW = 65399 RES = 0x00 ack urgp = 0
Aug 6 02:44:15 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 128TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18368 df proto = tcp spt = 1812 DPT = 22 WINDOW = 65399 RES = 0x00 ack psh urgp = 0
Aug 6 02:44:15 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 40TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18369 df proto = tcp spt = 1812 DPT = 22 WINDOW = 65535 RES = 0x00 ack urgp = 0
Aug 6 02:44:15 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 40TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18370 df proto = tcp spt = 1812 DPT = 22 WINDOW = 64395 RES = 0x00 ack urgp = 0
Aug 6 02:44:15 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 40TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18374 df proto = tcp spt = 1812 DPT = 22 WINDOW = 64327 RES = 0x00 ack urgp = 0
Aug 6 02:44:33 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 144TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18883 df proto = tcp spt = 1812 DPT = 22 WINDOW = 64327 RES = 0x00 ack psh urgp = 0
Aug 6 02:44:34 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 40TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18889 df proto = tcp spt = 1812 DPT = 22 WINDOW = 64259 RES = 0x00 ack urgp = 0
Aug 6 02:44:35 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 128TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18917 df proto = tcp spt = 1812 DPT = 22 WINDOW = 64259 RES = 0x00 ack psh urgp = 0
Aug 6 02:44:35 localhost kernel: IPTABLES: IN = eth0 OUT = MAC = 00: 0c: 29: 8f: 07: 60: 00: e0: 4d: b3: e3: 88: 08: 00SRC = 192.168.0.153 DST = 192.168.0.253LEN = 40TOS = 0x00 PREC = 0x00 TTL = 128 ID = 18924 df proto = tcp spt = 1812 DPT = 22 WINDOW = 64191 RES = 0x00 ack urgp = 0
Note:

1) first, confirm that the data packets you want to add to the LOG have not been discarded before;

2) then confirm that there is no ACCEPT rule in front of the LOG. If yes, delete the ACCEPT first and add it to the end of the ACCEPT to the LOG (that is, LOG first and then ACCEPT, otherwise, the system log cannot record the log information ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.