Skip to content

Commit 5525318

Browse files
author
Jonas Berg
committed
Avoid setting default gateway on Linux
Avoid setting it, as it will mess up the other network interfaces. However it is possible to override this new behavior in the corresponding bash script.
1 parent 0e48fbf commit 5525318

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/ports/linux/set_network_parameters

+13-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ SET_VALUES_PERMANENTLY=$6
3737
# name as station name internally.
3838
SKIP_SETTING_HOSTNAME=true
3939

40+
# The default gateway is typically used for non-Profinet traffic
41+
SKIP_SETTING_DEFAULT_GATEWAY=true
42+
4043
echo "Network script for ${INTERFACE}: " \
4144
"Set IP ${IP_ADDRESS} " \
4245
"Netmask ${NETMASK} " \
4346
"Gateway ${DEFAULT_GATEWAY} " \
4447
"Permanent: ${SET_VALUES_PERMANENTLY} " \
4548
"Hostname: ${HOSTNAME} " \
46-
"Skip setting hostname: ${SKIP_SETTING_HOSTNAME}"
49+
"Skip setting hostname: ${SKIP_SETTING_HOSTNAME} " \
50+
"Skip setting default gateway: ${SKIP_SETTING_DEFAULT_GATEWAY}"
4751

4852
# There is no need to set the changes permanently,
4953
# as the p-net stack will set the IP parameters on each start.
@@ -64,13 +68,15 @@ if ! ip link set dev $INTERFACE up; then
6468
exit 1
6569
fi
6670

67-
if [ "${DEFAULT_GATEWAY}" != "0.0.0.0" ]; then
68-
if ! ip route add default via $DEFAULT_GATEWAY; then
69-
echo "Failed to set default gateway"
70-
exit 1
71+
if [ "$SKIP_SETTING_DEFAULT_GATEWAY" = false ]; then
72+
if [ "${DEFAULT_GATEWAY}" != "0.0.0.0" ]; then
73+
if ! ip route add default via $DEFAULT_GATEWAY; then
74+
echo "Failed to set default gateway"
75+
exit 1
76+
fi
77+
else
78+
echo "No valid default gateway given. Skipping setting default gateway."
7179
fi
72-
else
73-
echo "No valid default gateway given. Skipping setting default gateway."
7480
fi
7581

7682
if [ "$SKIP_SETTING_HOSTNAME" = false ]; then

0 commit comments

Comments
 (0)