I want to know which way is better in the RHCE exam, is it better to use port number or service name when writing an iptable rule ?
For example, I usually do this to write a rule for pop3s
[root@linux-server /]# grep pop3s /etc/services
pop3s 995/tcp # POP-3 over SSL
pop3s 995/udp # POP-3 over SSL
[root@linux-server /]# iptables -A INPUT -s ! 192.168.1.0/24 -p tcp --dport 995 -j REJECT
[root@linux-server /]#
[root@linux-server /]# iptables -A INPUT -s ! 192.168.1.0/24 -p udp --dport 995 -j REJECT
[root@linux-server /]#
[root@linux-server /]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
REJECT tcp -- !192.168.1.0/24 anywhere tcp dpt:pop3s reject-with icmp-port-unreachable
REJECT udp -- !192.168.1.0/24 anywhere udp dpt:pop3s reject-with icmp-port-unreachable
[root@linux-server /]#
But I think this is easier to do:
[root@linux-server /]#
[root@linux-server /]# iptables -A INPUT -s ! 192.168.1.0/24 -p tcp --dport pop3s -j REJECT
[root@linux-server /]# iptables -A INPUT -s ! 192.168.1.0/24 -p udp --dport pop3s -j REJECT
[root@linux-server /]#
[root@linux-server /]#
[root@linux-server /]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
REJECT tcp -- !192.168.1.0/24 anywhere tcp dpt:pop3s reject-with icmp-port-unreachable
REJECT udp -- !192.168.1.0/24 anywhere udp dpt:pop3s reject-with icmp-port-unreachable
is there any preferred way ? for those who took the RHCE and passed, which way did you use ? did you use the port number or the service name ?