Score:0

Netplan config for either Static or DHCP depending on SSID connection

ke flag

I have a server that will either connect to one of two wireless SSIDs. On the first, I need a static IP and on the second, I need a DHCP IP. I know that I can set both a static IP and DHCP to true on the same interface and it works, but the default route always ends up being for the static IP so outbound connections always fail when connected to the DHCP network.

Is there something I am missing here? Is there a way to configure at the access point level whether to have a static IP or a DHCP IP so that the default route gets set correctly?

Below is my current Netplan wifis config:

  wifis:
    wlan0:
      optional: true
      dhcp-identifier: mac
      dhcp4: yes
      addresses: [10.86.180.86/23]
      gateway4: 10.86.180.1
      access-points:
        DHCPNet:
          password: "YYYYYYYYYYY"
        StaticNet:
          password: "XXXXXXXXXXX"

And the output from ip:

user@testsystem:~$ ip address show wlan0
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 8c:c6:81:31:74:64 brd ff:ff:ff:ff:ff:ff
    altname wlo1
    altname wlp0s20f3
    inet 10.86.180.86/23 brd 10.86.181.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet 10.1.1.106/24 brd 10.1.1.255 scope global dynamic wlan0
       valid_lft 7195sec preferred_lft 7195sec

also lshw -C network:

user@testsystem:~$ sudo lshw -C network
  *-network                 
       description: Wireless interface
       product: Cannon Point-LP CNVi [Wireless-AC]
       vendor: Intel Corporation
       physical id: 14.3
       bus info: pci@0000:00:14.3
       logical name: wlan0
       version: 30
       serial: 8c:c6:81:31:74:64
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=iwlwifi driverversion=5.11.0-38-generic firmware=46.4d093a30.0 9000-pu-b0-jf-b0- ip=10.1.1.106 latency=0 link=yes multicast=yes wireless=IEEE 802.11
       resources: irq:16 memory:dc31c000-dc31ffff
  *-network:0 DISABLED
       description: Ethernet interface
       physical id: 2
       bus info: usb@2:4
       logical name: wwan0
       serial: 0e:fc:a6:f7:e9:32
       capabilities: ethernet physical
       configuration: broadcast=yes driver=cdc_mbim driverversion=5.11.0-38-generic firmware=CDC MBIM link=no multicast=yes
  *-network:1
       description: Ethernet interface
       physical id: 3
       bus info: usb@4:1
       logical name: eth0
       serial: 8c:ae:4c:e9:61:13
       size: 1Gbit/s
       capacity: 1Gbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=ax88179_178a driverversion=5.11.0-38-generic duplex=full ip=10.1.1.107 link=yes multicast=yes port=MII speed=1Gbit/s
heynnema avatar
ru flag
How/where are you defining wlan0 to include wlo1 and wlp0s20f3? How does the server know which network to access for data/comm? I don't think that you can do what you request.
Thomas OHern avatar
ke flag
@heynnema - I belive those are autogenerated when I set: GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" in /etc/default/grub.The defaut route always ends up being through the statically assigned gateway, so despite the fact that I can connect to the server from th DHCP'd ip, I cannot make any connections from it.
heynnema avatar
ru flag
How many wireless interfaces do you have? Edit your question and show me `sudo lshw -C network`.
Thomas OHern avatar
ke flag
@heynnema - Just one wireless interface. output included in the edit above.
heynnema avatar
ru flag
Thanks for the info. I just don't think you can do this... at least I don't know how/if you can do it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.