Skip to content

Commit

Permalink
fix: DNS resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Dec 3, 2023
1 parent 6509303 commit 084367f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ configureDNS () {

for nameserver in "${nameservers[@]}"; do
nameserver=$(echo "$nameserver" | sed 's/#.*//' )
if ! [[ "$nameserver" =~ .*:.* ]]; then
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
fi
[[ "$nameserver" =~ .*:.* ]] && continue
[[ "$nameserver" == "127.0"* ]] && nameserver=$GATEWAY
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
done

[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="1.1.1.1"
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS=$GATEWAY

DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,$DNS_SERVERS --dhcp-option=option:router,${VM_NET_IP%.*}.1"

Expand Down Expand Up @@ -158,8 +158,6 @@ configureNAT () {
done

# Add internet connection to the VM
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)

iptables -t nat -A POSTROUTING -o "${VM_NET_DEV}" -j MASQUERADE
# shellcheck disable=SC2086
iptables -t nat -A PREROUTING -i "${VM_NET_DEV}" -d "${IP}" -p tcp $CONTROL_PORT_ARGS -j DNAT --to $VM_NET_IP
Expand Down Expand Up @@ -233,12 +231,10 @@ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null

VM_NET_MAC="${VM_NET_MAC//-/:}"
GATEWAY=$(ip r | grep default | awk '{print $3}')
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)

if [[ "${DEBUG}" == [Yy1]* ]]; then

IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
info "Container IP is ${IP} with gateway ${GATEWAY}" && echo

fi

if [[ "${DHCP}" == [Yy1]* ]]; then
Expand Down

0 comments on commit 084367f

Please sign in to comment.