Makers Blog

VLAN setup in PLCnext Technology

PLCnext Marcel 16 September 2022 min. read
36 views 0 comments

Currently on a PLCnext Control it is not possible to configure VLAN as easy as a static IP-address. But with some Linux knowledge, access to the terminal and the root account it is possible.

Let's start directly into the terminal as root and use the following three commands to setup a VLAN for the current session.

/sbin/ip link add link <DEVICE> name <NAME> type vlan id <VLAN_ID>
/sbin/ip addr add <VLAN_IP/MASK> dev <NAME>
/sbin/ip link set dev <NAME> up

First command ip link is adding a new network device configuration.

DEVICE specifies the physical device to act operate on.

NAME specifies the name of the new virtual device.

TYPE specifies the type of the new device. In our case the device is of type vlan.

VLAN_ID specifies the VLAN Identifier to use. Note that numbers with a leading " 0 " or " 0x " are interpreted as octal or hexadecimal, respectively.

The second command is adding the address and mask for our new device and the last one activates the vlan via setting the status to up or can also be used to deactivate it via down.

In the following example we are adding a vlan to our eth0 physical interface with the name eth0.99 and the id 99. Best practice here is to use the interface name and adding the id, to be able to identify your vlan faster.

/sbin/ip link add link eth0 name eth0.99 type vlan id 99
/sbin/ip addr add 192.168.1.10/24 dev eth0.99
/sbin/ip link set dev eth0.99 up

To make it persistent over reboots, just create an init.d script.

The script, in our example called vlan.sh, could be a very simple like the following one:

#!/bin/sh

start() {
        /sbin/ip link add link eth0 name eth0.99 type vlan id 99
        /sbin/ip addr add 192.168.1.10/24 dev eth0.99
        /sbin/ip link set dev eth0.99 up
}
stop() {
        /sbin/ip link set dev eth0.99 down
        /sbin/ip link delete eth0.99
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop &&
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
esac

It must be located at /etc/init.d/.

To register the script for the start-up, use the following command:

/usr/sbin/update-rc.d vlan.sh defaults 81

In the example a priority of 81 is used, to make sure, the network is up and running and the applications dependent on our vlan are probably not.

After a reboot you can use the following command to get some information about your vlan if it is up and running.

/sbin/ip -d link show eth0.99

And to stop the script launching on start-up use this command:

/usr/sbin/update-rc.d -f vlan.sh remove

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment
Login/Register
Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users