Networking

If you installed OpenBSD over the Internet, at least one Ethernet card should be configured and working. But if you installed from CD, you didn’t need to configure the network to install OpenBSD. If you installed OpenBSD on one network and want to move the machine to another network, you’ll need to reconfigure the network on your system.

I cover network principles in Chapter 11 and configuration in Chapter 12, but this brief entry will attach valid network addresses to your system, install a default route, and get DNS resolution working. If you’re not sure what to do here, don’t do anything until you read the later chapters.

To make network changes take effect, you can either reboot or run the network startup script /etc/netstart, like this:

# sh /etc/netstart

To configure only one interface, give the interface’s name as an argument:

# sh /etc/netstart em0

Again, if your system is a server, reboot before you declare the server ready for production.

Configuring Ethernet Interfaces

For a complete list of network interfaces recognized by your host, run ifconfig(8). You should see a bunch of entries, like this:

1 em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
          lladdr 00:0c:29:d2:37:be
          priority: 0
          groups: egress
          media: Ethernet autoselect (1000baseT full-duplex,master)
          status: active
2         inet 192.0.2.36 netmask 0xffffffe0 broadcast 192.0.2.63
          inet6 fe80::20c:29ff:fed2:37be%em0 prefixlen 64 scopeid 0x1

Every OpenBSD system comes with the default interfaces lo0 (loopback), enc0 (encapsulating interface), and pflog0 (PF logging, discussed in Chapter 21). These are virtual interfaces that don’t actually attach your system to the local Ethernet. Other interfaces will be physical network ports, like the Ethernet interface em0 at 1.

Every Ethernet card has its own configuration file, /etc/hostname .interfacename. The em0 interface in the example is configured in the file /etc/hostname.em0. If the file doesn’t exist, create it.

At 2, you see the IP address. The format of static IP addresses depends on the IP version in use.

Static IP Addresses

For IP version 4 (IPv4) addresses, the common format is as follows:

inet ipaddress netmask broadcastaddress options

This format includes these elements:

  • The inet keyword indicates this is an IPv4 address.

  • The IP address (ipaddress) appears in standard dotted-quad notation.

  • The netmask can appear in dotted-quad format (255.255.255.224) or in hexadecimal (0xffffffe0).

  • The broadcast address (broadcastaddress) gives you the option to hardcode the broadcast address on this network. If you leave this blank or use the word NONE, OpenBSD computes the correct broadcast address from the IP address and netmask given earlier. If you use ifconfig(8) options, you must use the word NONE to provide spacing. (You can also provide the netmask in “slash” notation directly after the IP address, as in 192.0.2.2/24.)

  • The options space is where you should put any specific ifconfig(8) commands needed for this interface, like hardcoded speed or duplex. (See Chapter 11 and Chapter 12 for examples, and the hostname.if(5) man page for the full details.)

When working with IP version 6 (IPv6) addresses, the format is as follows:

inet6 address prefixlength options

This format includes these elements:

  • The inet6 keyword tells the system that this is an IPv6 address.

  • The address space is for the IPv6 address, without a prefix length.

  • The prefix length (prefixlength) appears separately, without a slash.

  • As with IPv4, you can use ifconfig(8) options as needed.

Even a very simple configuration will get a machine on the network. The following configures em0 with the IPv4 address 192.0.2.2 and netmask 255.255.255.224. It also has the IPv6 address of 2001:DB8:7700::2/64.

$ cat /etc/hostname.em0
inet 192.0.2.2 255.255.255.224
inet6 2001:DB8::2 64

Anything that doesn’t follow these IPv4 and IPv6 formats is passed directly to ifconfig. However, if you don’t know if a particular configuration will work, try it at the command line first.

Dynamic Configuration

When performing dynamic configuration, if the machine is an IPv4 DHCP client, use the string dhcp in hostname.if. For IPv6 autoconfiguration, use the string rtsol, by itself on a single line, to tell OpenBSD to use the rtsol(8) IPv6 autoconfiguration program.

$ cat /etc/hostname.em0
dhcp
rtsol

In order for IPv6 autoconfiguration to work, you must disable IPv6 routing with these two entries in /etc/sysctl.conf:

net.inet6.ip6.forwarding=0
net.inet6.ip6.accept_rtadv=1

These values already exist in /etc/sysctl.conf, but they’re commented out.

Setting a Default Gateway

To set either the IPv4 or IPv6 default gateway, place the gateway IP address on a single line in /etc/mygate, with no other entries in the file. You can configure default gateways for both protocols, each on its own line. The change should take place on your next reboot, or use route(8) to manually change the default gateway. The following sets both an IPv4 and an IPv6 default gateway.

192.0.2.1
2001:DB8::1

Dynamic configuration requires setting a default route. If your /etc/hostname.if file contains a dynamic configuration statement, /etc/mygate will not be used for that IP protocol.

Setting Name Service Servers

If you want to contact other machines by hostname, you need to set Domain Name Service (DNS) servers.

Chapter 12 covers DNS resolution in detail, but /etc/resolv.conf contains the basic client settings. Its first line defines the local domain with the domain keyword and a domain name. Name servers appear on subsequent lines, defined with the keyword nameserver and an IP address, as shown here:

domain blackhelicopters.org
nameserver 192.0.2.1
nameserver 192.0.2.3
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.151.26