Skip to main content
added 244 characters in body
Source Link
MariusMatutiae
  • 4.4k
  • 1
  • 25
  • 36

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

This way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

EDIT:

as per FvD request:

systemctl stop network-manager
pkill dhclient
ip addr flush dev eth0   
systemctl start network-manager

if the interface in question is eth0, otherwise change accordingly.

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

This way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

This way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

EDIT:

as per FvD request:

systemctl stop network-manager
pkill dhclient
ip addr flush dev eth0   
systemctl start network-manager

if the interface in question is eth0, otherwise change accordingly.

added 70 characters in body
Source Link
MariusMatutiae
  • 4.4k
  • 1
  • 25
  • 36

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

InThis way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

This way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

Source Link
MariusMatutiae
  • 4.4k
  • 1
  • 25
  • 36

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
        case "$STATUS" in
                up) 
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
                ;;
                *)
                ;;
        esac
fi

In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.