Skip to content
Snippets Groups Projects

iproute-persistent

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Adphi
    Edited
    iproute-persistent 1.14 KiB
    #!/bin/sh
    
    save() {
            ip route > routes.save
    }
    
    restore() {
            if ! test -f routes.save; then
                    echo "routes.save not found"
                    exit 1;
            fi
            local default_route=""
            while read -r route; do
                    if echo "$route"|grep default > /dev/nul; then
                            default_route="$route"
                    elif ! ip route|grep "$route" > /dev/null; then
                            echo "adding: $route"
                            ip route add $route
                    fi
            done < routes.save
    
            if ! test -z "$default_route"; then
                    echo "adding default route: $default_route"
                    ip route add $default_route;
            fi
    }
    
    help() {
            echo "iproute-persistent"
            echo
            echo "Commands:"
            echo "  save    -- save routes to /etc/routes.save file"
            echo "  restore -- restore routes from /etc/routes.save"
    }
    
    case $1 in
            save)
                    save
            ;;
            restore)
                    restore
            ;;
            help | -h | --help)
            help
            ;;
            *)
            echo "unknown command $1"
            help
            ;;
    esac
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment