Path: blob/master/pkg/cidata/cidata.TEMPLATE.d/boot/09-host-dns-setup.sh
2658 views
#!/bin/sh12# SPDX-FileCopyrightText: Copyright The Lima Authors3# SPDX-License-Identifier: Apache-2.045set -eux67readonly chain=LIMADNS89chain_exists() {10iptables --table nat -n --list "${chain}" >/dev/null 2>&111}1213# Wait until iptables has been installed; 35-configure-packages.sh will call this script again14if command -v iptables >/dev/null 2>&1; then15if ! chain_exists; then16iptables --table nat --new-chain ${chain}17iptables --table nat --insert PREROUTING 1 --jump "${chain}"18iptables --table nat --insert OUTPUT 1 --jump "${chain}"19fi2021# Remove old rules22iptables --table nat --flush ${chain}23# Add rules for the existing ip:port24if [ -n "${LIMA_CIDATA_UDP_DNS_LOCAL_PORT}" ] && [ "${LIMA_CIDATA_UDP_DNS_LOCAL_PORT}" -ne 0 ]; then25iptables --table nat --append "${chain}" --destination "${LIMA_CIDATA_SLIRP_DNS}" --protocol udp --dport 53 --jump DNAT \26--to-destination "${LIMA_CIDATA_SLIRP_GATEWAY}:${LIMA_CIDATA_UDP_DNS_LOCAL_PORT}"27fi28if [ -n "${LIMA_CIDATA_TCP_DNS_LOCAL_PORT}" ] && [ "${LIMA_CIDATA_TCP_DNS_LOCAL_PORT}" -ne 0 ]; then29iptables --table nat --append "${chain}" --destination "${LIMA_CIDATA_SLIRP_DNS}" --protocol tcp --dport 53 --jump DNAT \30--to-destination "${LIMA_CIDATA_SLIRP_GATEWAY}:${LIMA_CIDATA_TCP_DNS_LOCAL_PORT}"31fi32fi333435