Commonly used targets are
1. ACCEPT
Sends packtes to other rule or process
2. DROP
Drops the packet silently. Remote machine will not be aware about what happend to the packet.
3. REJECT
When the rule met an error msg is send to client.
Eg of Reject:-
# iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT
4. REDIRECT
This is used to redirect a current traffic to a desired target. It is applied to PREROUTING chain of NAT table.
Eg:-
# iptables -t nat -A PREROUTING -p tcp --dport 3128 -j REDIRECT --to-port 80
# iptables -L -n -t nat -v
5. LOG
This allow us to log the traffic which meets the rules from the level of debug to emergency using syslog.
IPTable Logs:
It relies upon the kernel(kern) facility in syslog. So have to setup the syslog for logging the iptables activities.
Setup Logging
Primarily we enable the logging in IPTables
Enabling the Log for a chain
# iptables -I INPUT 1 -p tcp --dport 22 -j LOG
# iptables -L -n -v
# tail -f /var/log/messages
Configure syslog to log iptables activity separately:
We will change the facility to log to a seperate file
# vi /etc/syslog.conf
kern.none /var/log/messeges
kern.* /var/log/firewall.log
# service syslog reload
Test the Logging information by creating the traffic to port 22 on host.
# tail -f /var/log/firewall.log
brief about the log format:-
time- syslog facility - interface that revived the tracfic- MAC address of the remote system- MAC address of the local system - SRC IP- DSTIP - ID=packet sequence number - SPT=source port - DPT=destination port etc
Note:-
Generally logging should be enabled for separate chains & a specific rule. A catch all log for all the traffic will grow the log file numerously.
Loging All trafic
# iptables -A INPUT -j LOG
# tail -f /var/log/firewall.log
Log All except a perticular protocol from host 192.168.1.53
# iptables -I INPUT 1 -p tcp ! --dport 22 -src 192.168.1.53 -j LOG
# tail -f /var/log/firewall.log
Log Excluding Multiple port in single rule
# iptables -I INPUT 1 -m multiport -p tcp --dport !80,8080 -j LOG
# tail -f /var/log/firewall.log
Log using separate chains
Now we will check how to create a separate chain in IPTables for logging activities.
Create a New chain
# iptables -N LOGGER
# iptables -I INPUT 1 -j LOGGER
# iptables -A LOGGER -m multiport -p tcp --dport 21,22,80,143,8080 -j LOG
# tail -f /var/log/firewall.log
Loging the ssh access to the console.
In iptables:
Create a New CHAIN
# iptables -N SSHLOG
# iptables -I INPUT 1 -j SSHLOG
# iptables -A LOGGER -p tcp --dport 22 -j LOG
# vim /etc/syslog.conf
kern.* /dev/console
# service syslogd restart
Prefixing Interesting Traffic with a Log Prefix(--log-prefix "log prefix")
# iptables -A LOGGER -p tcp --dport 22 -j LOG --log-prefix "SSH Access Logs"
Note:-
The Maximum prefix length is 29 characters.
Note:-
--log-level (debug to emer)
This will decide the level of log from debug to emergency level.
No comments:
Post a Comment
tag ur valuable ideas below