{"id":1981,"date":"2018-04-27T15:29:04","date_gmt":"2018-04-27T15:29:04","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=1981"},"modified":"2018-09-15T17:56:53","modified_gmt":"2018-09-15T17:56:53","slug":"semanage-allow-and-delete-ports-in-centos","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/semanage-allow-and-delete-ports-in-centos\/","title":{"rendered":"semanage Allow and Delete ports in CentOS"},"content":{"rendered":"<p>The commands are for CentOS, but should work on Fedora and RedHat.<\/p>\n<p>If semanage is not installed refer to <a href=\"http:\/\/www.incredigeek.com\/home\/install-semanage-on-centos-7\/\">here<\/a>.<\/p>\n<p>You would typically use this along with the systems firewall to allow a port through.\u00a0 Guide for <a href=\"http:\/\/www.incredigeek.com\/home\/how-to-allow-a-port-through-firewalld\/\">firewalld<\/a> and <a href=\"http:\/\/www.incredigeek.com\/home\/how-to-open-a-port-on-redhat-centos-or-fedora-linux\/\">iptables<\/a>.\u00a0 If you change it in the firewall and fail to add\/edit it in semanage you can potentially get weird behavior like sshd not wanting to start after changing the port.<\/p>\n<p><strong>Add port<\/strong><\/p>\n<pre>semanage port -a -t ssh_port_t -p tcp 2222<\/pre>\n<p>The above command allows the sshd service to start, using port 2222.<\/p>\n<p><strong>List allowed ports<\/strong><\/p>\n<pre>semanage port -l<\/pre>\n<p>You can use grep to filter the results<\/p>\n<p>Example:<\/p>\n<pre>[admin@localhost ~]# semanage port -l | grep ssh\r\nssh_port_t tcp 2222, 22\r\n[admin@localhost ~]#<\/pre>\n<p><strong>Delete port<\/strong><\/p>\n<pre>semanage port -d -p tcp 2222<\/pre>\n<p><strong>Other examples<\/strong><\/p>\n<p>Allow SNMP<\/p>\n<pre>semanage port -a -t snmp_port_t -p udp 161<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The commands are for CentOS, but should work on Fedora and RedHat. If semanage is not installed refer to here. You would typically use this along with the systems firewall to allow a port through.\u00a0 Guide for firewalld and iptables.\u00a0 &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/semanage-allow-and-delete-ports-in-centos\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,4,24,3],"tags":[160,205,15,442,207,440,133,221],"class_list":["post-1981","post","type-post","status-publish","format-standard","hentry","category-centos-linux","category-command-line","category-fedora-2","category-linux","tag-firewall","tag-firewalld","tag-iptables","tag-port","tag-selinux","tag-semanage","tag-snmp-2","tag-ssh"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/1981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=1981"}],"version-history":[{"count":6,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/1981\/revisions"}],"predecessor-version":[{"id":2142,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/1981\/revisions\/2142"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=1981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=1981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=1981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}