nerves-networking / vintage_net_wifi

WiFi networking for VintageNet
Apache License 2.0
32 stars 18 forks source link

Static IP not working? #60

Closed mnishiguchi closed 3 years ago

mnishiguchi commented 3 years ago

Background

I attempted to configure static IP addresses for my three raspberry Pis (all model Zero W) using VintageNetWiFi. All I did is basically switch from DHCP to a minimal static IP setting. I see a few strange phenomena and the static IP is not working as expected.

Here is the setting I applied to all the device:

  config :vintage_net,
    regulatory_domain: "US",
    config: [
      {"usb0", %{type: VintageNetDirect}},
      {"eth0",
      %{
        type: VintageNetEthernet,
        ipv4: %{method: :dhcp}
      }},
      {"wlan0",
      %{
        type: VintageNetWiFi,
        vintage_net_wifi: %{
          networks: [
            %{
              key_mgmt: :wpa_psk,
              ssid: System.get_env("WIFI_SSID"),
              psk: System.get_env("WIFI_PSK")
            }
          ]
        },
-       ipv4: %{method: :dhcp}
+       ipv4: %{
+        method: :static,
+        address: "10.0.0.201",
+        prefix_length: 24
+      }
      }}
    ]

Problems

I see strange behavior in two patterns. I tweaked the setting by adding optional values such gateway and netmask but results were the same. I wonder if these are my setting specific or something is missing.

Device A

This one device is so stubborn that its IP is always 10.0.0.204 no matter what IP I specify in its config. This happens to be Nerves Livebook but I don't know if it is relevant.

Device B

My other two devices have correct IP addresses but it cannot access the Internet.

My local network

Screen Shot 2021-06-21 at 5 27 17 PM

Related links

fhunleth commented 3 years ago

This part of the configuration specifically disables Internet access (the default gateway isn't set), so I think what you're seeing is the right thing (i.e. right IP, no internet).

ipv4: %{
        method: :static,
        address: "10.0.0.201",
        prefix_length: 24
      }

Could you run VintageNet.info to check the runtime configuration? If you have a saved config, VintageNet uses that. The application config only specifies defaults. If you want to remove the saved configuration and go back to the default, run VintageNet.reset_to_defaults("wlan0").

mnishiguchi commented 3 years ago

Ah I see. My old config seems still alive as I run VintageNet.info on Device A.

...
Interface wlan0
  Type: VintageNetWiFi
  Present: true
  State: :configured (11.6 s)
  Connection: :internet (8.1 s)
  Addresses: ...
  Configuration:
    %{
      ipv4: %{method: :dhcp},  #<--- This is expected to be static
      type: VintageNetWiFi,
      vintage_net_wifi: %{
        networks: [
          %{
            key_mgmt: :wpa_psk,
            mode: :infrastructure,
            psk: "....",
            ssid: "..."
          }
        ]
      }
    }

After running VintageNet.reset_to_defaults("wlan0"), Device A now behaves like Device B.

The settings look good but I cannot connect to the Internet...

Interface wlan0
  Type: VintageNetWiFi
  Present: true
  State: :configured (15.4 s)
  Connection: :internet (12.4 s)
  Addresses: ...
  Configuration:
    %{
      ipv4: %{
        address: {10, 0, 0, 202},
        gateway: {10, 0, 0, 1},
        method: :static,
        name_servers: [{75, 75, 75, 75}, {75, 75, 76, 76}],
        prefix_length: 24
      },
      type: VintageNetWiFi,
      vintage_net_wifi: %{
        networks: [
          %{
            key_mgmt: :wpa_psk,
            mode: :infrastructure,
            psk: "....",
            ssid: "..."
          }
        ]
      }
    }

Next step

fhunleth commented 3 years ago

Could you change your name server to 1.1.1.1? You can access the internet, but DNS isn't working. This should fix that.

mnishiguchi commented 3 years ago

Thanks Frank. name_servers: [“1.1.1.1”] worked. Now I get a response from nerves-project.org.

       ipv4: %{
         method: :static,
         address: "10.0.0.202",
         prefix_length: 24,
         gateway: "10.0.0.1",
         name_servers: ["1.1.1.1"]
       }
mnishiguchi commented 3 years ago

After setting up the above mentioned, I cannot access Github including this page on Chrome (my main browser), I wonder if it is related to my Nerves network settings 🤔

mnishiguchi commented 3 years ago

Oh after a while, my Chrome works as normal 🤷