Where Everybody's Crazy

I'm a missionary in Japan. The name of my mission agency is WEC International. That's supposedly Worldwide Evangelisation for Christ, but I think I have a better idea about what it stands for...

2004-07-23

Far more than you ever wanted to know about OS X networking

Recently, I seem to have knackered my OS X installation; changes I make in System Preferences no longer affect the rest of the system. This is a pain, since I need to go around various places connecting to their networks and getting work done. Here are some of the things that I've found useful while hacking the network preferences.

First thing to note is that you can, of course, configure the basics - IP address and routing - using the standard Unix network tools. The one thing that will drive you mad until you work it out is how DNS lookups work.

The resolving in OS X post-Panther happens in two distinct parts: some things look at /etc/resolv.conf as you'd expect, but some things don't. These things look at lookupd, which is kind of the Mac nsswitch equivalent. We can look at its configuration here:

% lookupd -configuration
...
MaxIdleServers: 4
MaxIdleThreads: 2
MaxThreads: 64
TimeToLive: 43200
Timeout: 30
ValidateCache: YES
ValidationLatency: 15
_config_name: Global Configuration

LookupOrder: Cache FF DNS NI DS
_config_name: Host Configuration

...

The configuration consists of several sections, each ending in the _config_name tag. The one we're interested in is "Host Configuration", since that tells us how hosts get looked up. configd uses a number of "agents" that it consults in order to look up a host, user, or whatever; in this case, it looks up hosts in its own cache, then FF (flat files), then DNS, then NI (NetInfo) and then using DS (Directory Services). This is the default order of lookups - we don't actually need all of those agents, so we can speed up failing lookups by creating a file /etc/lookupd/hosts like so:

LookupOrder Cache DNS

A quick HUP of the lookupd process, and we're now using its internal cache and DNS. Note that lookupd doesn't specify how it uses DNS. We'll come back to that.

We can test that lookupd is giving the right answers by running lookupd -d - this is a handy debugging tool with tab completion and everything:

% lookupd -d
lookupd version 335 (root 2004.06.12 23:14:26 UTC)
Enter command name, "help", or "quit" to exit
> hostWithName: alibi.simon-cozens.org
Dictionary: "DNS: host alibi.simon-cozens.org"
_lookup_DNS_domain: simon-cozens.org
...

Hoorah, we found it. However, if it seems to hang when you press return after the host name - which it probably will if you're reading this because you can't get DNS working - then it's having problems looking things up in DNS.

lookupd is not one of the things that uses resolv.conf to find the DNS server, so what you put in there is irrelevant. You could try the second place that OS X keeps configuration data, in NetInfo; you can dump data in resolv.conf format:

% nidump resolv.conf .
domain simon-cozens.org
nameserver 127.0.0.1

(I find that using a local nameserver, by turning "-ON-" DNSSERVER in /etc/hostconfig is easier than running around trying to find where the nearest nameserver is as I move from place to place, especially since changing the name server is tricky if System Preferences is broken - as we're finding out.) But, maddeningly, you can't load stuff into NetInfo in that format. It turns out that you don't need to, since OS X keeps resolver information in a third place as well, but for the sake of fully documenting what's going on, the next stage is to create locations/resolver in netinfo if it doesn't already exist (yeah, I funted my NetInfo database as well) and then populate it with the right data:

% niutil -create . /locations/resolver
% niutil -createprop . /locations/resolver nameserver 127.0.0.1

Now we have played with lookupd and NetInfo, and probably you're finding that DNS still doesn't work. So it's time to move on to configd. configd is the thing which takes notifications from various parts of the system about configuration changes, and then fires off notifications to things that want to know about this. For instance, battery status events come from the kernel and get dispatched to things which put up that annoying "you're now running on reserve power" dialog.

What happened in my case was that configd stopped listening to System Preferences, so changes to the network configuration never got propagated to things which wanted to implement them. So we have to change the configuration by hand. If you're lucky enough that you have enough Locations set up to do what you want, you can use the scselect utility to change location:

% scselect Automatic

(This is the only way I know of to make DCHP work nicely when everything else is broken.) But if not, you're going to have to get hands dirty and change the configuration manually. We do this with scutil.

# scutil 
> open
> list
  subKey [0] = DirectoryService:PID
  subKey [1] = Plugin:IPConfiguration
...
  subKey [28] = Setup:/Network/Service/5CD6D0CE-E761-11D7-9AA7-0003935B54F8/DNS
...
> show Setup:/Network/Service/5CD6D0CE-E761-11D7-9AA7-0003935B54F8/DNS
<dictionary> {
  ServerAddresses : <array> {
    0 : 192.168.0.1
  }
}

Ooh no, we don't want that address. We want to change it to 127.0.0.1:

> get Setup:/Network/Service/5CD6D0CE-E761-11D7-9AA7-0003935B54F8/DNS
(This copies the dictionary to a local variable, d)
> d.remove ServerAddresses
> d.add ServerAddresses * 127.0.0.1

We need that "*" because ServerAddresses needs to be an array.

> set Setup:/Network/Service/5CD6D0CE-E761-11D7-9AA7-0003935B54F8/DNS

This sets the dictionary d back to the DNS configuration for our current location. Another HUP of lookupd, check /etc/resolv.conf, and DNS should be working for you - if not, you've got a few more places in OS X to play with than you had before. I have yet to explore what else can be done with scutil and playing with configd.


Posted at 11:36:48 in | # | G | P | 6 Comments
Language
Japanese English
Links

Tags and Tools
« 2004-07 »
S M TWTFS
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

RSS


I am...

lathos: Going from iPod 1.x to 2.x and severely regretting it.


Photoblog

DSC_5435.jpg

DSC_5440.jpg

DSC_5441.jpg

DSC_5444.jpg

DSC_5442.jpg


Speedblog

http://glosoli.blogspot.com/2005/09/encrypted-thumb-drive-and-autoplay.html # it's my blog: Encrypted thumb drive and autoplay howto

http://daiyainn.gooside.com/ # 京都だいや旅館 京へおこしやす

http://www.e-chords.com/guitartab.asp?idmusica=96629&keyb=true # Where Could I go Tab by Ben Harper - E-Chords

http://www.inmamaskitchen.com/RECIPES/RECIPES/Soups/vegetable_stock.html # Moosewood's Vegetable Stock Recipe

http://www.foodnetwork.com/food/recipes/recipe/0,,FOOD_9936_8389,00.html # Good Eats Roast Turkey Recipe: Recipes: Food Network

http://www.reallivepreacher.com/node/203 # You Ain't Jesus, PreacherPart Two: Losing The Language of Love

http://leiterreports.typepad.com/blog/2005/06/95_theses_on_th.html # Leiter Reports: A Philosophy Blog: 95 Theses on the Religious Right

http://cbae.nmsu.edu/~dboje/teaching/338/traits.htm # TRAITS

http://jweb.kokken.go.jp/gitaigo/index.html # 擬音語・擬態語 - 日本語を楽しもう! -

http://www.nanzan-u.ac.jp/SHUBUNKEN/publications/jjrs/jjrs_cumulative_list.htm # Japanese Journal of Religious Studies: Cumulative list of Essays & Book Reviews

http://www.myspace.com/chloecfrancis # www.myspace.com/chloecfrancis

http://www.solar.ifa.hawaii.edu/cgi-bin/StrikeProb?latitude=+35.38&longitude=-136.26&location=Nagahama,+Japan # Tropical Cyclone Strike Probabilities for Nagahama, Japan

http://www.missionjapan.org/mission/jmissionorg.html # Japan Mission Organization List

http://www.aquasapone.com.au/soapmaking/showergel_soap.html # AquaSapone - How to make shower gel from natural handmade soap

http://www.ultimate-guitar.com/tabs/d/danilo_montero/la_unica_razon_crd.htm # La Unica Razon Chords by Danilo Montero @ Ultimate-Guitar.Com


Musicblog

The Flaming Lips – Approaching Pavonis Mons by Balloon (Utopia Planitia)

The Cult – She Sells Sanctuary

Dar Williams – Alleluia

Powered by Glob!
Search: