Set IP address (dhcpcd)
DHCP is enabled by default in delivery state. If there is no DHCP server in the network, TwinCAT/BSD automatically assigns an IP address (169,254.x.x) after a timeout of five seconds. The alternative is a fixed IP address. In this work step you will be shown how to set a fixed IP address in the console in a system with dhcpcd.
These settings are alternatively possible via the web interface of the Beckhoff Device Manager (see: Beckhoff Device Manager: web interface).
Proceed as follows:
- 1. Enter
ifconfig
in the console in order to query the network configuration. The Ethernet interfacesigb0
andigb1
of an industrial PC with two interfaces are listed in this sample. The interfaceigb1
is active and connected to a network.
igb0: flags=8863<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4a024a9<RXCSUM,VLAN_MTU,JUMBO_MTU,VLAN_HWCSUM,LRO,WOL_MAGIC,RXCSUM_IPV6,NOMAP>
ether 00:01:05:3d:69:12
inet6 fe80::25b2:4227:1a65:b77a%igb0 prefixlen 64 scopeid 0x1
inet 169.254.228.5 netmask 0xffff0000 broadcast 169.254.255.255
media: Ethernet autoselect
status: no carrier
nd6 options=1<PERFORMNUD>
igb1: flags=8863<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4a024a9<RXCSUM,VLAN_MTU,JUMBO_MTU,VLAN_HWCSUM,LRO,WOL_MAGIC,RXCSUM_IPV6,NOMAP>
ether 00:01:05:3d:69:13
inet6 fe80::4207:801c:e08a:9ede%igb1 prefixlen 64 scopeid 0x2
inet 172.17.42.57 netmask 0xfffffc00 broadcast 172.17.43.255
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
nd6 options=1<PERFORMNUD>
- 2. Enter
doas ee /etc/rc.conf
in the console.
The filerc.conf
opens in the editor. - 3. Use the arrow keys to navigate below the entry
dhcpcd_enable="YES"
and add the following line:
ifconfig_igb1="inet 192.168.25.25 netmask 255.255.255.0"
- 4. Note the order of the entries in the configuration file. The system reads configuration files from top to bottom. Configuring a static IP address after the DHCP configuration overwrites the previous DHCP configuration.
- 5. Define the IP address with
inet
and the subnet mask for the Ethernet interfaceigb1
withnetmask
. - 6. Add the parameter
--denyinterfaces igb1
to the entrydhcpcd_flags
to disable DHCP for this interface. Otherwise, the interface receives two IP addresses. A fixed IP address that you have defined and additionally an IP address from the DHCP server. You can skip this step if this behavior is desired.
dhcpcd_flags="--waitip --denyinterfaces igb1"
- 7. If DHCP is to be disabled for multiple interfaces, they can be listed separated by commas.
dhcpcd_flags="--waitip --denyinterfaces igb1,igb0"
- 8. Press [Esc] and select the option
a) leave editor
and subsequentlya) save changes
.
- You have successfully set
192.168.25.25
as the fixed IP address. Enter the commanddoas service netif restart && doas service dhcpcd restart
in the console to have the settings applied. Use the commanddoas sh -c "service netif restart && service dhcpcd restart"
when accessing the system via SSH. Then check the network settings with the commandifconfig
.