# How do I use a static IP address with wireless networking?



## ikevin8me (Jun 11, 2022)

Dynamic IP for wireless works:
in /etc/wpa_supplicant.conf

```
network={
  ssid="Name with spaces"
  psk="freebsdmall"
}
```
and in /etc/rc.conf

```
wlans_ath0="wlan0"
ifconfig_wlan0="WPA DHCP"
```









						Chapter 33. Advanced Networking
					

Advanced networking in FreeBSD:  basics of gateways and routes, CARP, how to configure multiple VLANs on FreeBSD, etc




					docs.freebsd.org
				




I tried to set a static IP to my wireless networking but it just didn't work. Also, the wireless SSID name has spaces (and I can't change it) and also a password (psk) is needed. How can I resolve this problem?


----------



## hruodr (Jun 11, 2022)

ikevin8me said:


> ifconfig_wlan0="WPA DHCP"


Instead of "WPA DHCP" put "inet XXX.XXX.XXX.XXX"


----------



## ikevin8me (Jun 11, 2022)

That’s what I did. But it did not log on to the wireless router.


----------



## ikevin8me (Jun 11, 2022)

I tried "ifconfig_wlan0="WPA NOSYNCDHCP"" and it didn't work. 

I tried "WPA inet XXX.XXX.XXX.XXX..." and it didn't work as well.

What I need is to log on to the wireless router and at the same time set the static IP. I wonder how can I do it?


----------



## tuxador (Jun 11, 2022)

just in case: the XXX.XXX.XXX.XXX must be the static IP adress you've assigned.


----------



## T-Daemon (Jun 11, 2022)

Set

```
ifconfig_wlan0="WPA inet <IP>"
```
eventually set `ssid`:

```
ifconfig_wlan0="WPA inet <IP> ssid <SSID of wireless router>"
```

Mandatory set default router:

```
defaultrouter="<IP of wireless router>"
```

Restart services:

`service netif restart`
`service routing restart`


----------



## ikevin8me (Jun 11, 2022)

Well, those "ifconfig_wlan0="WPA inet <IP> ssid <SSID of wireless router>"", etc. didn't work. It simply said "no carrier" on the status when I did a "ifconfig wlan0".

The ssid has spaces (I cannot change it), so I put single-quote with it. However, I don't think this is the reason it didn't work.


----------



## T-Daemon (Jun 11, 2022)

ikevin8me said:


> It simply said "no carrier" on the status when I did a "ifconfig wlan0".



Have you set `defaultrouter` and restarted the services? I've checked on my system, it works fine.


----------



## ikevin8me (Jun 11, 2022)

Yes, I did.

I'd like to confirm: what can I do to set an ssid with spaces? Do I put it in single-quotes?


----------



## T-Daemon (Jun 11, 2022)

ikevin8me said:


> ... what can I do to set an ssid with spaces? Do I put it in single-quotes?


Single-quotes will do.

Try setting the `country` code and `regdomain` . Check /etc/regdomain.xml for your country, i.e.:

```
create_args_wlan0="country GB regdomain ETSI"
```

Restart netif service after setting.


----------



## ikevin8me (Jun 11, 2022)

Well, it does not work. DHCP just work fine. :-( I'm not sure what to do now... I need to configure the firewall and hope the DHCP address stays all the same.


----------



## Phishfry (Jun 11, 2022)

hruodr said:


> Instead of "WPA DHCP" put "inet XXX.XXX.XXX.XXX"


I believe you are missing the subnet mask with this.

ifconfig wlan0= "WPA inet 000.000.000.000 netmask 000.000.000.000"
or
ifconfig wlan0="WPA inet 000.000.000.000/00"

Example for class C subnet:
ifconfig wlan0="WPA inet 192.168.1.100/24"
or
ifconfig wlan0="WPA inet 192.168.1.100 netmask 255.255.255.0"


----------



## hruodr (Jun 11, 2022)

Phishfry said:


> I believe you are missing the subnet address with this.


You are right. I seldom do it and get something like

inet 10.0.0.1 netmask 0xff000000 broadcast 10.255.255.255


----------



## hruodr (Jun 11, 2022)

ikevin8me said:


> I need to configure the firewall and hope the DHCP address stays all the same.


You can do that sure at sever side, on the router, assignation according to the mac address.


----------



## Kiiski (Jun 12, 2022)

ikevin8me said:


> I need to configure the firewall and hope the DHCP address stays all the same.



Might not be appropriate at your situation or I might have misunderstood above comment, but in pf that is not a problem:

pf.conf()

`Host name resolution and interface to address translation are done
at ruleset load-time. When the address of an interface (or host
name) changes (under DHCP or PPP, for instance), the ruleset must
be reloaded for the change to be reflected in the kernel. Sur-
rounding the interface name (and optional modifiers) in parentheses
changes this behaviour. When the interface name is surrounded by
parentheses, the rule is automatically updated whenever the inter-
face changes its address. The ruleset does not need to be
reloaded. This is especially useful with [I]nat.[/I]`


----------



## SirDice (Jun 17, 2022)

hruodr said:


> You are right. I seldom do it and get something like
> 
> inet 10.0.0.1 netmask 0xff000000 broadcast 10.255.255.255


10.x.x.x is a class A network. This classful designation isn't used much anymore, it's mostly _classless_ nowadays. But many TCP/IP tools still fallback to this old behavior if you don't supply a subnet mask. 









						Classful network - Wikipedia
					






					en.wikipedia.org


----------



## Minbari (Jun 17, 2022)

eg. /etc/rc.conf:

```
ifconfig_wlan0="WPA inet 192.168.1.XX netmask 255.255.255.0 ssid 'XYZQPZ'"
defaultrouter="192.168.Q.Z"
create_args_wlan0="country XY regdomain FCC4"
```

/etc/resolv.conf: 

```
nameserver 192.168.Q.Z
```


----------



## bakul (Jun 17, 2022)

ikevin8me said:


> Also, the wireless SSID name has spaces (and I can't change it) and also a password (psk) is needed. How can I resolve this problem?


You can use bssid, which is typically a MAC  (ethernet) address instead of an ssid string. See wpa_supplicant.conf(7)


----------

