| #!/bin/bash |
| # Copyright 2021 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| iptables -P INPUT DROP -w |
| iptables -P FORWARD DROP -w |
| iptables -P OUTPUT DROP -w |
| |
| # Accept everything on the loopback |
| iptables -I INPUT -i lo -j ACCEPT -w |
| iptables -I OUTPUT -o lo -j ACCEPT -w |
| |
| # Accept return traffic inbound |
| iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -w |
| |
| # Accept all inbound TCP/UDP/ICMP/SCTP packets |
| iptables -A INPUT -p tcp -j ACCEPT -w |
| iptables -A INPUT -p udp -j ACCEPT -w |
| iptables -A INPUT -p icmp -j ACCEPT -w |
| iptables -A INPUT -p sctp -j ACCEPT -w |
| |
| # Accept all forwarded TCP/UDP/ICMP/SCTP packets |
| iptables -A FORWARD -p tcp -j ACCEPT -w |
| iptables -A FORWARD -p udp -j ACCEPT -w |
| iptables -A FORWARD -p icmp -j ACCEPT -w |
| iptables -A FORWARD -p sctp -j ACCEPT -w |
| |
| # Accept new and return traffic outbound |
| iptables -I OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT -w |