Skip to content

Instantly share code, notes, and snippets.

@nickkostov
Created January 9, 2025 17:12
Show Gist options
  • Select an option

  • Save nickkostov/b605df329647c470fae995b68b0b1e7c to your computer and use it in GitHub Desktop.

Select an option

Save nickkostov/b605df329647c470fae995b68b0b1e7c to your computer and use it in GitHub Desktop.

Revisions

  1. nickkostov created this gist Jan 9, 2025.
    55 changes: 55 additions & 0 deletions network-settings-check.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #!/bin/bash

    # Function to check distribution type
    check_distro() {
    if [ -f /etc/os-release ]; then
    . /etc/os-release
    DISTRO=$ID
    else
    echo "Unable to determine the distribution type."
    exit 1
    fi
    }

    # Main script
    check_distro

    # Print network configuration
    echo "\n####################### Network Configuration #######################"
    ifconfig 2>/dev/null || ip addr

    echo "\n######################### /etc/hosts File ##########################"
    cat /etc/hosts

    echo "\n####################### /etc/resolv.conf File ######################"
    cat /etc/resolv.conf

    # Handle systemd-resolved files
    echo "\n####################### Systemd Resolved Config #####################"
    if [ "$DISTRO" == "debian" ] || [ "$DISTRO" == "ubuntu" ]; then
    if [ -f /etc/systemd/resolved.conf ]; then
    echo "\n/etc/systemd/resolved.conf:"
    cat /etc/systemd/resolved.conf
    else
    echo "File not found: /etc/systemd/resolved.conf"
    fi

    if [ -f /run/systemd/resolve/resolv.conf ]; then
    echo "\n/run/systemd/resolve/resolv.conf:"
    cat /run/systemd/resolve/resolv.conf
    else
    echo "File not found: /run/systemd/resolve/resolv.conf"
    fi
    elif [ "$DISTRO" == "rhel" ] || [ "$DISTRO" == "centos" ] || [ "$DISTRO" == "fedora" ]; then
    if [ -f /etc/systemd/resolved.conf ]; then
    echo "\n/etc/systemd/resolved.conf:"
    cat /etc/systemd/resolved.conf
    else
    echo "File not found: /etc/systemd/resolved.conf"
    fi
    else
    echo "Unsupported distribution: $DISTRO"
    exit 1
    fi

    echo "\n#####################################################################"