Network Manager script when interface up?
Because I am using Bionic Beaver/Ubuntu 18.04, the network settings in /etc/network/interfaces
are being ignored and the settings in /etc/NetworkManager/system-connections/'eth0'
are being used for i) static ip ii) gateway etc.
I wish to restart the sshd service every time the interface comes up. It doesn't work in the normal place /etc/network/interfaces
since I'm using Gnome. Where can I place a NetworkManager script to be run every time a specific interface comes up?
network-manager
add a comment |
Because I am using Bionic Beaver/Ubuntu 18.04, the network settings in /etc/network/interfaces
are being ignored and the settings in /etc/NetworkManager/system-connections/'eth0'
are being used for i) static ip ii) gateway etc.
I wish to restart the sshd service every time the interface comes up. It doesn't work in the normal place /etc/network/interfaces
since I'm using Gnome. Where can I place a NetworkManager script to be run every time a specific interface comes up?
network-manager
1
/etc/network/interfaces
no longer controls networking in 18.04. It is managed by netplan. I suggest that you transfer your settings there. netplan.io/examples
– chili555
Jan 21 at 14:47
@chili555 not 100% accurate. The /etc/netplan/*.yaml file can be set to use NetworkManager, just like the good old days.
– heynnema
Jan 21 at 18:43
add a comment |
Because I am using Bionic Beaver/Ubuntu 18.04, the network settings in /etc/network/interfaces
are being ignored and the settings in /etc/NetworkManager/system-connections/'eth0'
are being used for i) static ip ii) gateway etc.
I wish to restart the sshd service every time the interface comes up. It doesn't work in the normal place /etc/network/interfaces
since I'm using Gnome. Where can I place a NetworkManager script to be run every time a specific interface comes up?
network-manager
Because I am using Bionic Beaver/Ubuntu 18.04, the network settings in /etc/network/interfaces
are being ignored and the settings in /etc/NetworkManager/system-connections/'eth0'
are being used for i) static ip ii) gateway etc.
I wish to restart the sshd service every time the interface comes up. It doesn't work in the normal place /etc/network/interfaces
since I'm using Gnome. Where can I place a NetworkManager script to be run every time a specific interface comes up?
network-manager
network-manager
asked Jan 21 at 13:18
JSStuballJSStuball
1234
1234
1
/etc/network/interfaces
no longer controls networking in 18.04. It is managed by netplan. I suggest that you transfer your settings there. netplan.io/examples
– chili555
Jan 21 at 14:47
@chili555 not 100% accurate. The /etc/netplan/*.yaml file can be set to use NetworkManager, just like the good old days.
– heynnema
Jan 21 at 18:43
add a comment |
1
/etc/network/interfaces
no longer controls networking in 18.04. It is managed by netplan. I suggest that you transfer your settings there. netplan.io/examples
– chili555
Jan 21 at 14:47
@chili555 not 100% accurate. The /etc/netplan/*.yaml file can be set to use NetworkManager, just like the good old days.
– heynnema
Jan 21 at 18:43
1
1
/etc/network/interfaces
no longer controls networking in 18.04. It is managed by netplan. I suggest that you transfer your settings there. netplan.io/examples– chili555
Jan 21 at 14:47
/etc/network/interfaces
no longer controls networking in 18.04. It is managed by netplan. I suggest that you transfer your settings there. netplan.io/examples– chili555
Jan 21 at 14:47
@chili555 not 100% accurate. The /etc/netplan/*.yaml file can be set to use NetworkManager, just like the good old days.
– heynnema
Jan 21 at 18:43
@chili555 not 100% accurate. The /etc/netplan/*.yaml file can be set to use NetworkManager, just like the good old days.
– heynnema
Jan 21 at 18:43
add a comment |
1 Answer
1
active
oldest
votes
The solution is to create dispatchers scripts in /etc/NetworkManager/dispatcher.d
. For example, you could log events in journald
by placing the following script at /etc/NetworkManager/dispatcher.d/log-iface-events.sh
:
#!/usr/bin/env bash
interface=$1
event=$2
echo "$interface received $event" | systemd-cat -p info -t dispatch_script
Remember to give it execution permissions:
chmod +x /etc/NetworkManager/dispatcher.d/log-iface-events.sh
The bad news is that scripts are no longer tied to a given interface or events such as up or down. Hence, you must check all of that in your script. If you want this script to run only for eth0
, you must filter that by hand putting something like the following in your script:
[[ $interface == "eth0" ]] || return 0
For example:
#!/usr/bin/env bash
interface=$1
event=$2
if [[ $interface != "eth0" ]] || [[ $event != "up" ]]
then
return 0
fi
# place your commands bellow this line
Will run only if it is dealing with up
events for eth0
interface.
You can have many scripts. According to man 8 networkmanager
, scripts will run in alphabetical order. This seems to include the scripts in subdirectories. You MUST read this manpage.
Inside my/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named01-ifupdown
. Exactly where should I put my commands? :/
– JSStuball
Jan 21 at 13:56
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the01-ifupdown
is the sole executable file in thedispatcher.d
directory after installation?
– JSStuball
Jan 21 at 16:31
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old/etc/network/if-up.d
and/etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.
– PEdroArthur
Jan 27 at 2:59
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1111652%2fnetwork-manager-script-when-interface-up%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The solution is to create dispatchers scripts in /etc/NetworkManager/dispatcher.d
. For example, you could log events in journald
by placing the following script at /etc/NetworkManager/dispatcher.d/log-iface-events.sh
:
#!/usr/bin/env bash
interface=$1
event=$2
echo "$interface received $event" | systemd-cat -p info -t dispatch_script
Remember to give it execution permissions:
chmod +x /etc/NetworkManager/dispatcher.d/log-iface-events.sh
The bad news is that scripts are no longer tied to a given interface or events such as up or down. Hence, you must check all of that in your script. If you want this script to run only for eth0
, you must filter that by hand putting something like the following in your script:
[[ $interface == "eth0" ]] || return 0
For example:
#!/usr/bin/env bash
interface=$1
event=$2
if [[ $interface != "eth0" ]] || [[ $event != "up" ]]
then
return 0
fi
# place your commands bellow this line
Will run only if it is dealing with up
events for eth0
interface.
You can have many scripts. According to man 8 networkmanager
, scripts will run in alphabetical order. This seems to include the scripts in subdirectories. You MUST read this manpage.
Inside my/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named01-ifupdown
. Exactly where should I put my commands? :/
– JSStuball
Jan 21 at 13:56
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the01-ifupdown
is the sole executable file in thedispatcher.d
directory after installation?
– JSStuball
Jan 21 at 16:31
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old/etc/network/if-up.d
and/etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.
– PEdroArthur
Jan 27 at 2:59
add a comment |
The solution is to create dispatchers scripts in /etc/NetworkManager/dispatcher.d
. For example, you could log events in journald
by placing the following script at /etc/NetworkManager/dispatcher.d/log-iface-events.sh
:
#!/usr/bin/env bash
interface=$1
event=$2
echo "$interface received $event" | systemd-cat -p info -t dispatch_script
Remember to give it execution permissions:
chmod +x /etc/NetworkManager/dispatcher.d/log-iface-events.sh
The bad news is that scripts are no longer tied to a given interface or events such as up or down. Hence, you must check all of that in your script. If you want this script to run only for eth0
, you must filter that by hand putting something like the following in your script:
[[ $interface == "eth0" ]] || return 0
For example:
#!/usr/bin/env bash
interface=$1
event=$2
if [[ $interface != "eth0" ]] || [[ $event != "up" ]]
then
return 0
fi
# place your commands bellow this line
Will run only if it is dealing with up
events for eth0
interface.
You can have many scripts. According to man 8 networkmanager
, scripts will run in alphabetical order. This seems to include the scripts in subdirectories. You MUST read this manpage.
Inside my/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named01-ifupdown
. Exactly where should I put my commands? :/
– JSStuball
Jan 21 at 13:56
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the01-ifupdown
is the sole executable file in thedispatcher.d
directory after installation?
– JSStuball
Jan 21 at 16:31
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old/etc/network/if-up.d
and/etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.
– PEdroArthur
Jan 27 at 2:59
add a comment |
The solution is to create dispatchers scripts in /etc/NetworkManager/dispatcher.d
. For example, you could log events in journald
by placing the following script at /etc/NetworkManager/dispatcher.d/log-iface-events.sh
:
#!/usr/bin/env bash
interface=$1
event=$2
echo "$interface received $event" | systemd-cat -p info -t dispatch_script
Remember to give it execution permissions:
chmod +x /etc/NetworkManager/dispatcher.d/log-iface-events.sh
The bad news is that scripts are no longer tied to a given interface or events such as up or down. Hence, you must check all of that in your script. If you want this script to run only for eth0
, you must filter that by hand putting something like the following in your script:
[[ $interface == "eth0" ]] || return 0
For example:
#!/usr/bin/env bash
interface=$1
event=$2
if [[ $interface != "eth0" ]] || [[ $event != "up" ]]
then
return 0
fi
# place your commands bellow this line
Will run only if it is dealing with up
events for eth0
interface.
You can have many scripts. According to man 8 networkmanager
, scripts will run in alphabetical order. This seems to include the scripts in subdirectories. You MUST read this manpage.
The solution is to create dispatchers scripts in /etc/NetworkManager/dispatcher.d
. For example, you could log events in journald
by placing the following script at /etc/NetworkManager/dispatcher.d/log-iface-events.sh
:
#!/usr/bin/env bash
interface=$1
event=$2
echo "$interface received $event" | systemd-cat -p info -t dispatch_script
Remember to give it execution permissions:
chmod +x /etc/NetworkManager/dispatcher.d/log-iface-events.sh
The bad news is that scripts are no longer tied to a given interface or events such as up or down. Hence, you must check all of that in your script. If you want this script to run only for eth0
, you must filter that by hand putting something like the following in your script:
[[ $interface == "eth0" ]] || return 0
For example:
#!/usr/bin/env bash
interface=$1
event=$2
if [[ $interface != "eth0" ]] || [[ $event != "up" ]]
then
return 0
fi
# place your commands bellow this line
Will run only if it is dealing with up
events for eth0
interface.
You can have many scripts. According to man 8 networkmanager
, scripts will run in alphabetical order. This seems to include the scripts in subdirectories. You MUST read this manpage.
edited Jan 27 at 2:55
answered Jan 21 at 13:33
PEdroArthurPEdroArthur
39127
39127
Inside my/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named01-ifupdown
. Exactly where should I put my commands? :/
– JSStuball
Jan 21 at 13:56
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the01-ifupdown
is the sole executable file in thedispatcher.d
directory after installation?
– JSStuball
Jan 21 at 16:31
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old/etc/network/if-up.d
and/etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.
– PEdroArthur
Jan 27 at 2:59
add a comment |
Inside my/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named01-ifupdown
. Exactly where should I put my commands? :/
– JSStuball
Jan 21 at 13:56
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the01-ifupdown
is the sole executable file in thedispatcher.d
directory after installation?
– JSStuball
Jan 21 at 16:31
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old/etc/network/if-up.d
and/etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.
– PEdroArthur
Jan 27 at 2:59
Inside my
/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named 01-ifupdown
. Exactly where should I put my commands? :/– JSStuball
Jan 21 at 13:56
Inside my
/etc/NetworkManager/dispatcher.d
I have 3 sub-directories and one executable named 01-ifupdown
. Exactly where should I put my commands? :/– JSStuball
Jan 21 at 13:56
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
@JSStuball I made changes to address your question.
– PEdroArthur
Jan 21 at 15:15
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the
01-ifupdown
is the sole executable file in the dispatcher.d
directory after installation?– JSStuball
Jan 21 at 16:31
Please could you(/someone) address 1) how the choice of script filename affects behaviour, and 2) why the
01-ifupdown
is the sole executable file in the dispatcher.d
directory after installation?– JSStuball
Jan 21 at 16:31
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old
/etc/network/if-up.d
and /etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.– PEdroArthur
Jan 27 at 2:59
@JSStuball I addressed the first point. About the second, it seems to bridge the functionalities of the old
/etc/network/if-up.d
and /etc/network/if-up.d
with network-manager, but I suspect it will be deprecated soon.– PEdroArthur
Jan 27 at 2:59
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1111652%2fnetwork-manager-script-when-interface-up%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
/etc/network/interfaces
no longer controls networking in 18.04. It is managed by netplan. I suggest that you transfer your settings there. netplan.io/examples– chili555
Jan 21 at 14:47
@chili555 not 100% accurate. The /etc/netplan/*.yaml file can be set to use NetworkManager, just like the good old days.
– heynnema
Jan 21 at 18:43