Skip to content

Commit

Permalink
Avoid setting default gateway on Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jonas Berg committed May 10, 2024
1 parent 0e48fbf commit 5525318
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/ports/linux/set_network_parameters
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ SET_VALUES_PERMANENTLY=$6
# name as station name internally.
SKIP_SETTING_HOSTNAME=true

# The default gateway is typically used for non-Profinet traffic
SKIP_SETTING_DEFAULT_GATEWAY=true

echo "Network script for ${INTERFACE}: " \
"Set IP ${IP_ADDRESS} " \
"Netmask ${NETMASK} " \
"Gateway ${DEFAULT_GATEWAY} " \
"Permanent: ${SET_VALUES_PERMANENTLY} " \
"Hostname: ${HOSTNAME} " \
"Skip setting hostname: ${SKIP_SETTING_HOSTNAME}"
"Skip setting hostname: ${SKIP_SETTING_HOSTNAME} " \
"Skip setting default gateway: ${SKIP_SETTING_DEFAULT_GATEWAY}"

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

if [ "${DEFAULT_GATEWAY}" != "0.0.0.0" ]; then
if ! ip route add default via $DEFAULT_GATEWAY; then
echo "Failed to set default gateway"
exit 1
if [ "$SKIP_SETTING_DEFAULT_GATEWAY" = false ]; then
if [ "${DEFAULT_GATEWAY}" != "0.0.0.0" ]; then
if ! ip route add default via $DEFAULT_GATEWAY; then
echo "Failed to set default gateway"
exit 1
fi
else
echo "No valid default gateway given. Skipping setting default gateway."
fi
else
echo "No valid default gateway given. Skipping setting default gateway."
fi

if [ "$SKIP_SETTING_HOSTNAME" = false ]; then
Expand Down

0 comments on commit 5525318

Please sign in to comment.