# Static IP troubles



## poobert (Jun 4, 2009)

I have read the handbook many times and as expansive as it is perhaps I am missing something.

To set a static IP I merely have to specify such a thing in the rc.conf?
i try   

```
ifconfig_ral0="ssid myssid inet theipiwant netmask 255.255.255.0"
ifconfig_ral0="WPA"
```

this associates the wireless ral0 with my SSID ,but doesn't give it the IP i specified.

If I manually type 
	
	



```
$ifconfig ral0 inet 192.168.1.100
```
, it's happy though.

wpa_supplicant seems to work fine also. 
My brain am fried from trying to figure this out alone.


----------



## vivek (Jun 4, 2009)

Did you restarted networking service after updating /etc/rc.conf? 

```
/etc/rc.d/netif restart && /etc/rc.d/routing restart
```
Do you see any specific error on screen?


----------



## SirDice (Jun 4, 2009)

Why use static IP addresses on wireless?


----------



## rocky (Jun 4, 2009)

poobert said:
			
		

> I have read the handbook many times and as expansive as it is perhaps I am missing something.
> 
> To set a static IP I merely have to specify such a thing in the rc.conf?
> i try
> ...



You should use


```
ifconfig_ral0="ssid myssid inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255"
```


----------



## SirDice (Jun 4, 2009)

Having had a look at /etc/network.subr and /etc/rc.d/netif try this:


```
ifconfig_ral0="WPA ssid myssid inet 192.168.1.100 netmask 255.255.255.0"
```

In your config the second ifconfig_ral0 overruled the first.


----------



## phoenix (Jun 4, 2009)

In shell scripting, the last setting of a variable is the only one that gets used.  Hence, only the last ifconfig_ral0 setting is actually used.

Either put it all in one line, with WPA first (as shown by SirDice), or split it into two commands using the aliasing features of rc.conf:

```
ifconfig_ral0="WPA"
ifconfig_ral0_alias0="inet 192.168.1.100 netmask 255.255.255.0"
```

Be sure to put all the correct info into /etc/wpa_supplicant.conf for the network.

(You need to do the wireless link config first, as setting some of the wireless link info resets the higher level networking info like the IP and netmask.)


----------



## poobert (Jun 4, 2009)

Now my rc.conf includes these lines:


```
defaultrouter="192.168.1.1"
ifconfig_ral0="WPA ssid thessid inet 192.168.1.101 netmask 255.255.255.0"
```
including the broadcast address doesn't work either.

After a reboot, ral0's status is asscociated with the proper ssid, the WPA seems to have worked but still no IP address.

Why not use wireless with a static IP?


----------



## SirDice (Jun 5, 2009)

poobert said:
			
		

> Why not use wireless with a static IP?


It more or less defeats the purpose of being able to connect anything everywhere, all you need is the wireless key.

It's also pretty pointless if you do it to 'secure' your wireless. This includes using MAC address filtering.


----------



## adriaan (Jul 9, 2010)

*This works for me*

In /etc/rc.conf:


```
wlans_ath0="wlan0"
ifconfig_wlan0="WPA inet a.b.c.d netmask 0xffffff00"
defaultrouter="a.b.c.e"
```

and in /etc/resolv.conf:

```
nameserver "f.g.h.i"
```

ie - just like Wireless DHCP, but in stead of DHCP in the ifconfig line, just add the static config.


----------



## overflowing (Jun 7, 2011)

I too was trying to get a static IP with WPA going and couldn't get it working but by following adriaan's post it's now working.  Specifically adding the defaultrouter line to rc.conf made it work.  I personally did not have to edit the resolv.conf file because it already had values set (I guess from when I was connected via dhcp?)


----------



## BoggledByBSD (Aug 19, 2016)

Sorry if it's poor form to dig up an old post, but this was one of my first big stumps when I was trying to tune my original networking configuration. I pretty much got the same response as to my attempts to static a wireless connection as "why". To me, you don't want to static everything obviously, as wireless and DHCP do go hand-in-hand with the convenience of the devices, and there is little to no security increase in staticing the connection. However, after getting more advanced in my usage of FreeBSD networking, by installing samba server using version samba44 and the latest FreeBSD 10.3 version, I keep coming back to why I was never able to get my main wireless device to work as static.

It's pretty complicated for me now, as what I've done as the sensible workaround to staticing the IP using the OS, is to set up my networking hardware to use a static DHCP configuration.

And the reason you would want to static, and I still would like to static the OS, is that as my configuration in FreeBSD becomes more complicated, for example, using the packet filter starting with a block all rule, setting a Samba server up that needs to know right from boot what IP to use, PF rules need to go through as smoothly and quickly as possible, etc - is that the OS knows right from the get-go what IP to grab, and doesn't get it confused with other devices, nor does it take any time to try to acquire a lease, making everything work more smoothly.

So I feel like I'm passing the buck to my networking hardware to do what the OS should simply do, but I have never gotten any of these supposed static wireless configurations to work. I mean, look at my rc.conf now, I can easily post it because I just dropped it on my workstation I'm typing on because I can do that now having figured out samba, even with the added complexity PF "block all" configurations add, forcing you to define every little way out and in of your network by hand, etc -

/etc/rc.conf:

```
hostname="localhost"
#ifconfig_re0="inet 192.168.8.1 netmask 255.255.255.240"
#defaultrouter="192.168.8.1"
local_unbound_enable="YES"
moused_enable="YES"
ntpd_enable="YES"
powerd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"

hald_enable="YES"
dbus_enable="YES"
ifconfig_re0="up"
wlans_ath0="wlan0"
ifconfig_ath0="ether mac address"
ifconfig_wlan0="WPA"
cloned_interfaces="lagg0"
ifconfig_lagg0="laggproto failover laggport re0 laggport wlan0 DHCP"
samba_server_enable="YES"
pf_enable="YES"
pflog_enable="YES"
fusefs_enable="YES"
#devfs_system_ruleset="system"
```

And here's me experimenting with PF, still able to go from a host to a router to a firewall then to my workstation, but still can't understand where I would go from here to get static IP working on wireless, but I must be doing something right if I am able to share my files with windows across all that network topology:

/etc/pf.conf


```
block log all
table <local> { 192.168.0.0/28 }
pass in log quick from <local> to any keep state
tcp_pass = "{ 25 80 123 137 138 445}"
udp_pass = "{ 53 137 138}"
pass out log on lagg0 proto tcp to any port $tcp_pass keep state
pass out log on lagg0 proto udp to any port $udp_pass keep state
```

I'm able to browse the internet, drop files to my windows machine, and view PF in action with `tcpdump -n -e -ttt -i pflog0`, see all the stuff that I didn't specificially allow in or out simply bounce off, or what happens to the packets(part of why I'm posting this is because PF is perhaps the single most beautiful piece of open source software I've come across, coming from linux crap like iptables, being a network geek, I am amazed by PF).

And I might as well also show you the samba config I cooked up myself with a lot of googling. All this is very makeshift, but I can put files on my windows machine across 2 firewalls, and windows can't make any changes to the FreeBSD machine(I guess I actually have what would be called a server now?), and even see the connections open and the pings bounce off with `pftop`.

/user/local/smb4.conf


```
[global]
domain master = yes
local master = yes
preferred master = yes
workgroup = WORKGROUP
server string = "Server"
#netbios name = Winix
#wins support = yes
hosts allow = 192.168.0.
security = user
passdb backend = tdbsam

[BSD]
path = /home/user/Downloads
valid users = user
writable = no
browsable = yes
read only = yes
guest ok = no
public = no
create mask = 0665
directory mask = 0755
```

So, I've managed to do all this, but things would be running quite a bit smoother if I could just get the FreeBSD machine to choose the IP address instead of forcing my router to look for its MAC address to assign one statically.

This isn't meant as a complaint, and I am truly thankful for all the help I've received along the way here, and with what I've been able to accomplish with FreeBSD ensures I will never use any linux distribution again. The developers under the BSD license sure have their stuff together in comparison to a lot of the linux distro's out there.

So this is truely my "Boggle", as my name would imply, as happy as I am with everything, I would just like to see how I would get a static IP working from here, especially after all I've accomplished on my own. But don't get me wrong, the boggle I have for BSD is truly that of how well and consistently designed it is. I understand if you don't want to help, but just consider this a thanks and a sign of gratitude for all the people on these forums and the friends I've met along the way who have helped me get started in the land of true UNIX.


----------



## SirDice (Aug 19, 2016)

In your case it's probably as simple as changing this line:

```
ifconfig_lagg0="laggproto failover laggport re0 laggport wlan0 DHCP"
```
To:

```
ifconfig_lagg0="laggproto failover laggport re0 laggport wlan0 inet 192.168.8.1 netmask 255.255.255.0"
```

Don't forget about defaultrouter and perhaps adjusting unbound.


----------



## BoggledByBSD (Aug 19, 2016)

SirDice said:


> In your case it's probably as simple as changing this line:
> 
> ```
> ifconfig_lagg0="laggproto failover laggport re0 laggport wlan0 DHCP"
> ...



I'm not sure what to do with the unbound files. I think I understand their their purpose as a type of local DNS cache/proxy/resolver, but there are quite a few files in a few directorys throughout my system and none of them point to anything but dns servers, and this problem takes place before DNS.

If I copy and paste the line you gave me, and simply change:

```
DHCP"
```
to 

```
inet 192.168.8.1 netmask 255.255.255.0
```
,
Then at the point at boot when rc.conf reaches the lagg proto, it reads:


```
lagg0: link changed to DOWN
ifconfig inet: bad value
```

The strange thing is if I keep the system on for a little bit afterwards, ifconfig eventually reads "associated", and my router says the connection has been established but no data is passing through.

Also, if i just configure the wired cable with the exact same settings and the defaultrouter line uncommented, it will work with no problem static.

The way the system just tells me "bad value" with the line that you added(and i have tried before, of course, but not after the lagg failover), makes me think there's either something way above my head, or there must be another way of configuring the value.

I always have uncommented the defaultrouter line, added the inet part, and then all I get when i use ping or anything is "no route to host".


----------



## SirDice (Aug 19, 2016)

BoggledByBSD said:


> If I copy and paste the line you gave me, at the point at boot when rc.conf reaches the lagg proto, it reads:
> 
> 
> ```
> ...


Oops. I think you just need to remove the inet keyword. For some reason the syntax is slightly different for lagg(4).



> The strange thing is if I keep the system on for a little bit afterwards, ifconfig eventually reads "associated", and my router says the connection has been established but no data is passing through.


Yes, the wireless part will still do its "thing", you just don't have an IP address so there's no connectivity on layer 3.


----------



## BoggledByBSD (Aug 19, 2016)

Got it! That was it in this case, just the simple syntax removal of inet.


----------

