{"id":1593,"date":"2016-10-27T14:10:33","date_gmt":"2016-10-27T19:10:33","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1593"},"modified":"2016-10-28T08:46:26","modified_gmt":"2016-10-28T13:46:26","slug":"iptables-and-deletingreplacing-entries","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2016\/10\/iptables-and-deletingreplacing-entries\/","title":{"rendered":"iptables and deleting\/replacing entries"},"content":{"rendered":"<p>Whenever I have to reboot my modem [sic] at home, I typically get a new IP address from my ISP.<\/p>\n<p>When that happens, I need to update iptables to allow my new address to connect to the SSH port (port 22) of my jump box (which, fortunately, I have access to from another IP address):<\/p>\n<p><code>iptables -A INPUT -p tcp -m state --state NEW -s [new IP address] --dport 22 -j ACCEPT<\/code><\/p>\n<p>But I don&#8217;t want to leave the old entry. How to get rid of it?<\/p>\n<p>The delete (<code>-D<\/code>) and replace (<code>-R<\/code>) options require a line number from the chain (e.g. the INPUT chain). To find the line numbers:<\/p>\n<p><code>iptables -L INPUT --line-numbers<\/code><\/p>\n<p>To delete the existing rule and add the new rule:<\/p>\n<p><code>iptables -D INPUT [line number]<br \/>\niptables -A INPUT -p tcp -m state --state NEW --dport 22 -s [new IP address] -j ACCEPT<\/code><\/p>\n<p>To replace the existing entry:<\/p>\n<p><code>iptables -R INPUT [line number] -p tcp -m state --state NEW --dport 22 -s [new IP address] -j ACCEPT<\/code><\/p>\n<p>Save the updates so they are persistent:<\/p>\n<p><code>iptables-save &gt; \/etc\/iptables\/rules.v4<\/code><\/p>\n<p>(That&#8217;s the location for Debian and Ubuntu. This may be different for your distribution.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whenever I have to reboot my modem [sic] at home, I typically get a new IP address from my ISP. When that happens, I need to update iptables to allow my new address to connect to the SSH port (port 22) of my jump box (which, fortunately, I have access to from another IP address): &hellip; <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2016\/10\/iptables-and-deletingreplacing-entries\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">iptables and deleting\/replacing entries<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[232],"tags":[409,408,196],"class_list":["post-1593","post","type-post","status-publish","format-standard","hentry","category-tips-tricks","tag-firewall","tag-iptables","tag-linux"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1593"}],"version-history":[{"count":7,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1593\/revisions"}],"predecessor-version":[{"id":1601,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1593\/revisions\/1601"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}