{"id":150,"date":"2018-07-15T21:23:15","date_gmt":"2018-07-15T21:23:15","guid":{"rendered":"http:\/\/www.linuxauthority.com\/wordpress\/?p=150"},"modified":"2018-07-15T21:23:15","modified_gmt":"2018-07-15T21:23:15","slug":"the-firewall-project","status":"publish","type":"post","link":"https:\/\/www.linuxauthority.com\/wordpress\/?p=150","title":{"rendered":"The firewall project"},"content":{"rendered":"\n<!-- ALL ADSENSE ADS DISABLED -->\n<p>Converting a fairly elaborate iptables based firewall with proprietary anti-spam scripts to the modern firewall-command architecture without revealing any IP.<\/p>\n<p>First lets take a look where we started:<\/p>\n<p>[root@instance-5 ~]# systemctl list-unit-files | egrep &#8220;iptables|firewall&#8221;<br \/>\nfirewalld.service masked<br \/>\niptables.service disabled<br \/>\n<a href=\"http:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.43.10-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-154\" src=\"http:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.43.10-PM.png\" alt=\"\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.43.10-PM.png 1920w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.43.10-PM-300x169.png 300w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.43.10-PM-768x432.png 768w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.43.10-PM-1024x576.png 1024w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>This shows iptables as disabled but a lot of scripts have been adding entries none the less<\/p>\n<p><a href=\"http:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.50.17-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-156\" src=\"http:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.50.17-PM.png\" alt=\"\" width=\"1090\" height=\"801\" srcset=\"https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.50.17-PM.png 1090w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.50.17-PM-300x220.png 300w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.50.17-PM-768x564.png 768w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.50.17-PM-1024x752.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Most of these firewall rules relate to blocking spam smtp\/mail servers. I kind f like to screw with those foks.<\/p>\n<p>Lets clean out these entries:<\/p>\n<p>iptables -F;iptables -L -n<\/p>\n<p><a href=\"http:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.57.30-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-158\" src=\"http:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.57.30-PM.png\" alt=\"\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.57.30-PM.png 1920w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.57.30-PM-300x169.png 300w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.57.30-PM-768x432.png 768w, https:\/\/www.linuxauthority.com\/wordpress\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-10-at-9.57.30-PM-1024x576.png 1024w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>Now we need to stop cron from running any scripts and causing trouble.<\/p>\n<p>1014 systemctl disable crond<br \/>\n1015 systemctl stop crond<\/p>\n<p>We will get a jump start with system-config-firewall<\/p>\n<p>We will need to nkow which ports must remain open to service a databse cluster and the servers secondary DNS worload.<\/p>\n<p>[root@instance-5 ~]# netstat -an |grep LISTEN<br \/>\ntcp 0 0 127.0.0.1:10026 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 127.0.0.1:783 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 172.17.0.1:53 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 10.240.0.3:53 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:4567 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 127.0.0.1:10024 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN<br \/>\ntcp 0 0 127.0.0.1:10025 0.0.0.0:* LISTEN<br \/>\ntcp6 0 0 ::1:10026 :::* LISTEN<br \/>\ntcp6 0 0 :::110 :::* LISTEN<br \/>\ntcp6 0 0 ::1:783 :::* LISTEN<br \/>\ntcp6 0 0 :::143 :::* LISTEN<br \/>\ntcp6 0 0 :::111 :::* LISTEN<br \/>\ntcp6 0 0 :::8080 :::* LISTEN<br \/>\ntcp6 0 0 :::80 :::* LISTEN<br \/>\ntcp6 0 0 :::8081 :::* LISTEN<br \/>\ntcp6 0 0 :::53 :::* LISTEN<br \/>\ntcp6 0 0 :::21 :::* LISTEN<br \/>\ntcp6 0 0 :::22 :::* LISTEN<br \/>\ntcp6 0 0 ::1:953 :::* LISTEN<br \/>\ntcp6 0 0 :::25 :::* LISTEN<br \/>\ntcp6 0 0 :::443 :::* LISTEN<br \/>\ntcp6 0 0 :::993 :::* LISTEN<br \/>\ntcp6 0 0 :::995 :::* LISTEN<br \/>\ntcp6 0 0 ::1:10024 :::* LISTEN<\/p>\n<p>[root@instance-5 ~]# systemctl start firewalld.service<br \/>\nFailed to start firewalld.service: Unit is masked.<br \/>\n[root@instance-5 ~]# systemctl unmask firewalld<br \/>\nRemoved symlink \/etc\/systemd\/system\/firewalld.service.<br \/>\n[root@instance-5 ~]# systemctl enable firewalld<br \/>\nCreated symlink from \/etc\/systemd\/system\/dbus-org.fedoraproject.FirewallD1.service to \/usr\/lib\/systemd\/system\/firewalld.service.<br \/>\nCreated symlink from \/etc\/systemd\/system\/multi-user.target.wants\/firewalld.service to \/usr\/lib\/systemd\/system\/firewalld.service.<br \/>\n[root@instance-5 ~]# systemctl start firewall<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;state<\/p>\n<p>running<\/p>\n<p>[root@instance-5 ~]# firewall-cmd &#8211;get-default-zone<br \/>\ntrusted<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;get-active-zones<br \/>\ntrusted<br \/>\ninterfaces: eth0<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;get-services<br \/>\nRH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server<br \/>\n[root@instance-5 ~]#<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=https<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=smtp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=dns<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=wbem-https<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=smtps<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=smtps &#8211;permanent<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=smtp &#8211;permanent<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=dns &#8211;permanent<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=https &#8211;permanent<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;add-service=http &#8211;permanent<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;list-services<br \/>\nsmtps smtp dns https http<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=4567\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=10024\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=10025\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=10026\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=53\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=53\/udp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=111\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=143\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;add-port=993\/tcp<br \/>\nsuccess<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;list-services<br \/>\nsmtps smtp dns https http<br \/>\n[root@instance-5 ~]# firewall-cmd &#8211;zone=trusted &#8211;permanent &#8211;list-ports<br \/>\n4567\/tcp 10024\/tcp 10025\/tcp 10026\/tcp 53\/tcp 53\/udp 111\/tcp 143\/tcp 993\/tcp<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>This is taking the IP address list from my proprietary anti-spam software and creating firewall commands.<\/p>\n<p>The command:firewall-cmd it&#8217;s not as easy to be direct with the script as is IP tables.<\/p>\n<p>Yet I managed to get this code working with difficulty.<\/p>\n<p>&nbsp;<\/p>\n<p>ffile is set to \/tmp\/fffile stands for firewall file.<\/p>\n<p>\/bin\/cat mail.iplist | while read -r ip<\/p>\n<p>do<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 <\/span>echo &#8220;${iswlist} ${iswl} &#8230; &#8221;<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 <\/span>iswlist=$(\/bin\/grep ${ip} whitelist.ip.perm | wc -l );<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 <\/span>iswl=$(\/bin\/grep ${ip} whitelist.ip | wc -l );<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 <\/span>if [ $iswl -eq 0 ] &amp;&amp; [ $iswlist -eq 0 ]<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 <\/span>then<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>echo &#8220;ip: $(ip)&#8221;<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>echo firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-rich-rule=\\&#8217;rule family=&#8221;ipv4&#8243; source address=&#8221;$ip&#8221; port protocol=&#8221;tcp&#8221; port=&#8221;25&#8243; reject\\&#8217; &gt;&gt; ${ffile}<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0 <\/span>fi<\/p>\n<p>done<\/p>\n<p>cat ${ffile} | while read -r CMD<\/p>\n<p>do<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0<\/span>echo $CMD<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0<\/span>ksh &#8220;${CMD}&#8221;<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0<\/span>rc=$?<\/p>\n<p><span class=\"Apple-converted-space\">\u00a0<\/span>echo &#8220;$rc $CMD ..&#8221;<\/p>\n<p>done<\/p>\n<p>firewall-cmd &#8211;complete-reload<\/p>\n<p>sleep 50<\/p>\n<p>firewall-cmd &#8211;zone=public &#8211;list-all<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Converting a fairly elaborate iptables based firewall with proprietary anti-spam scripts to the modern firewall-command architecture without revealing any IP. First lets take a look where we started: [root@instance-5 ~]# systemctl list-unit-files | egrep &#8220;iptables|firewall&#8221; firewalld.service masked iptables.service disabled &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; This shows iptables as disabled but a [&hellip;]<\/p>\n<a role=\"link\" class=\"rtp-readmore\" title=\"Read more on The firewall project\" href=\"https:\/\/www.linuxauthority.com\/wordpress\/?p=150\" rel=\"nofollow\">Read More &rarr;<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,21],"tags":[32,30,34,36],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-networking","category-systems-administration","tag-direweall","tag-firewall","tag-firewall-cmd","tag-iptables"],"_links":{"self":[{"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/150"}],"collection":[{"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150"}],"version-history":[{"count":4,"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions\/166"}],"wp:attachment":[{"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxauthority.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}