Commit Diff


commit - 6b6b0dbf7c439f6bed9d156f42b6508d85234cc6
commit + 99fce0e7c014d5b936886e9702bc0620b8b07d75
blob - /dev/null
blob + 81fbb9cefdd682e849ea3942ee4506f1c31c6b55 (mode 644)
--- /dev/null
+++ wiki.d/Hostnameif.Static-v2
@@ -0,0 +1,20 @@
+version=pmwiki-2.2.130 ordered=1 urlencoded=1
+agent=Mozilla/5.0 (X11; OpenBSD amd64; rv:91.0) Gecko/20100101 Firefox/91.0
+author=theguest
+charset=UTF-8
+csum=
+ctime=1653281922
+host=38.87.162.129
+name=Hostnameif.Static-v2
+rev=2
+targets=Openbsd.Buyvm,Openbsd.Vmmuser,Unbound.Configure,Openbsd.Ping,Openbsd.Netcat,Openbsd.Traceroute
+text=(:title Configuring Static Networking:)%0a%0aMost computer users don't have to deal with networking because they use DHCP, where the router automatically figures out and assigns networking settings to each device, such as: the client's IP address, default gateway and DNS servers. %0a%0aHowever, if you are running a server, it's important to configure static networking so that your IP addresses don't change in an unpredictable manner. Static networking is preferred to get reliable IPv4 and IPv6 networking.%0a%0aIf you chose DHCP when first installing OpenBSD, you will need to follow the steps below to configure the networking manually.%0a%0a'''WARNING''': Make sure you warn any connected users before attempting to change your networking. Any mistakes here can cause all your users to get disconnected. If you are worried about making mistakes, you should practice first on a separate server. Please also be prepared to use the serial console ([[openbsd/buyvm|BuyVM]] or [[openbsd/vmmuser|training VPS]]) in case ssh stops working.%0a%0a!! hostname.if%0a%0aOpenBSD requires one hostname.if per networking interface, where the letters 'if' are replaced with an abbreviation followed by a device number. For example, if you have a virtio networking interface, it will be abbreviated by vio, so you will need an /etc/hostname.vio0 file.%0a%0aIt is this file that controls if this interface is configured to use DHCP  (see [[https://man.openbsd.org/dhclient.8 | dhclient(8)]]) for its network configuration OR uses a Static config (however a Static config requires editing other config-files as well). %0a%0a'''Note''': If you chose DHCP when first installing OpenBSD, then your hostname.if will probably contain just one line: '[@inet autoconf@]' or '[@dhcp@]' (which is just an alias for '[@inet autoconf@]'). IPV6 would use the (extra) line: '[@inet6 autoconf@]'. %0a%0a!!! Setting up Static Networking%0a%0aInside /etc/hostname.if (where you replace if with your device), you should put something similar to the following lines:%0a%0a[@%0ainet 192.168.1.2 255.255.255.0%0ainet alias 192.168.1.3 255.255.255.0%0ainet6 2001:0db8:0000:0000:0000:0000:0000:0000 48%0ainet6 alias 2001:0db8:0000:0000:9b1d:3511:387e:143a 48%0ainet6 alias 2001:0db8:0000:0000:1465:fed1:8daf:66ff 48%0ainet6 alias 2001:0db8:0000:0000:11b4:4a36:2941:d6bd 48%0ainet6 alias 2001:0db8:0000:0000:ad2c:5b99:2b1a:89d1 48%0ainet6 alias 2001:0db8:0000:0000:921d:28ad:4729:8d93 48%0a@]%0a%0aNote: Do '''not''' use those exact IP addresses. Use the real IP addresses you were assigned by your ISP.%0a%0aLet's look at the first two lines:%0a%0a[@%0ainet 192.168.1.2 255.255.255.0%0ainet alias 192.168.1.3 255.255.255.0%0a@]%0a%0aThe first line will set the device to use the static IP 192.168.1.2 with subnet mask 255.255.255.0. The second line will allow the device to use a second static IP, 192.168.1.3. It will be aliased to the first and have the same subnet mask.%0a%0aIt makes sense to have an aliased IP address when two or more IP addresses share the exact same networking interface. You will see this being done if you have one normal IPv4 address and a DDoS filtered IPv4 address. Both of them actually share the same networking interface, so the unfiltered IPv4 address is actually an alias of the filtered one.%0a%0aLet's look at lines 3 and 4:%0a%0a[@%0ainet6 2001:0db8:0000:0000:0000:0000:0000:0000 48%0ainet6 alias 2001:0db8:0000:0000:9b1d:3511:387e:143a 48%0a@]%0a%0aThe first line sets the device to use the static IPv6 address 2001:0db8:: with a /48 subnet, and the second one creates another IPv6 address 2001:0db8:0000:0000:9b1d:3511:387e:143a with a /48 subnet, aliased to the first IPv6 address. Each time you need a new IPv6 address, just add a new aliased IPv6 address. In this way, you can create dozens of unique IPv6 addresses so that each user on a shell account or bouncer can get a unique IPv6 address.%0a%0a!! Default Gateway%0a%0aThe default gateway is the router that your server is connected to. This is where all the IP packets from your server will immediately forward its packets to. The default gateway will be provided by your ISP.%0a%0aSince we disabled the DHCP client, we must also now manually config the default gateway.%0a%0aIn the file /etc/mygate, you specify the default gateway:%0a%0a[@%0a192.168.1.1%0a2001:0db8:0000:0000::1%0a@]%0a%0aYou should have received the gateway addres(ses) from your provider. In the example above you see an IP4 and IP6 address.%0a%0a%0a!! DNS Servers%0a%0aUnless you already specified your custom DNS servers or set up your own local DNS such as [[Unbound/configure | Unbound]], then your system now no longer knows what DNS server to query (since the DHCP-client is now disabled). %0a%0aIn the file /etc/resolv.conf we add our nameservers, such as in the example below:%0a%0a[@%0alookup file bind%0anameserver 9.9.9.9%0a@]%0a%0aThe keyword '[@nameserver@]' is followed by the IP4/IP6 address of the DNS server that you want your system to use. As always, check the ([[https://man.openbsd.org/resolv.conf.5 | manpage]]) for additional options.%0a%0a'''Note''': '[@lookup@]' specifies which databases should be searched, and the order to do so. [@bind@] = Query a domain name server; [@file@] = Search for entries in /etc/hosts.%0a%0a%0a!! Restart Networking%0a%0aTo restart networking, run:%0a%0a[@%0a$ doas sh /etc/netstart%0a@]%0a%0aIf this doesn't properly reset the networking, you can do the following:%0a%0a'''WARNING''': This will definitely disconnect all network connections.%0a%0a[@%0a$ doas ifconfig if0 down%0a$ doas route flush%0a$ doas sh /etc/netstart%0a@]%0a%0a'''Note''': Make sure to replace if0 with your real device.%0a%0a'''HINT''': Obviously, if you do this over ssh, your network would go down after the first command, disallowing you from entering the commands to get the network back up. We put the commands on one line seperated by a semicolon to pass all three so that we may reconnect after the network is back up.%0a%0a[@%0a$ doas ifconfig if0 down; doas route flush; doas sh /etc/netstart%0a@]%0a%0a%0a!! ifconfig%0a%0aYou can add new IPv4 addresses on the fly, without rebooting, by using ifconfig:%0a%0a[@%0a$ doas ifconfig if0 alias 192.168.1.3 255.255.255.0%0a@]%0a%0aFor IPv6:%0a%0a[@%0a$ doas ifconfig if0 inet6 2001:0db8::/48%0a@]%0a%0aTo delete an IPv4 address:%0a%0a[@%0a$ doas ifconfig if0 192.168.1.3 delete%0a@]%0a%0aTo delete the IPv6 address:%0a%0a[@%0a$ doas ifconfig if0 inet6 2001:0db8::/48 delete%0a@]%0a%0aNote: replace if0 with your specific interface, and replace the IP addresses and subnet masks.%0a%0aTo test if an IP address is working, you can use [[openbsd/ping|ping]], [[openbsd/netcat|netcat]], and [[openbsd/traceroute|traceroute]].%0a
+time=1653287373
+title=Configuring Static Networking
+author:1653287373=theguest
+diff:1653287373:1653281922:minor=85c85%0a%3c '''Note''': '[@lookup@]' specifies which databases should be searched, and the order to do so. [@bind@] = Query a domain name server; [@file@] = Search for entries in /etc/hosts.%0a---%0a> '''Note''': '[@lookup@]' specifies which databases should be searched, and the order to do so. [@bind@] = Query a domain name server [@file@] = Search for entries in /etc/hosts.%0a
+host:1653287373=38.87.162.129
+author:1653281922=theguest
+csum:1653281922=as requested by jrmu, fork of https://wiki.ircnow.org/index.php?n=Hostnameif.Static
+diff:1653281922:1653281922:=1,143d0%0a%3c (:title Configuring Static Networking:)%0a%3c %0a%3c Most computer users don't have to deal with networking because they use DHCP, where the router automatically figures out and assigns networking settings to each device, such as: the client's IP address, default gateway and DNS servers. %0a%3c %0a%3c However, if you are running a server, it's important to configure static networking so that your IP addresses don't change in an unpredictable manner. Static networking is preferred to get reliable IPv4 and IPv6 networking.%0a%3c %0a%3c If you chose DHCP when first installing OpenBSD, you will need to follow the steps below to configure the networking manually.%0a%3c %0a%3c '''WARNING''': Make sure you warn any connected users before attempting to change your networking. Any mistakes here can cause all your users to get disconnected. If you are worried about making mistakes, you should practice first on a separate server. Please also be prepared to use the serial console ([[openbsd/buyvm|BuyVM]] or [[openbsd/vmmuser|training VPS]]) in case ssh stops working.%0a%3c %0a%3c !! hostname.if%0a%3c %0a%3c OpenBSD requires one hostname.if per networking interface, where the letters 'if' are replaced with an abbreviation followed by a device number. For example, if you have a virtio networking interface, it will be abbreviated by vio, so you will need an /etc/hostname.vio0 file.%0a%3c %0a%3c It is this file that controls if this interface is configured to use DHCP  (see [[https://man.openbsd.org/dhclient.8 | dhclient(8)]]) for its network configuration OR uses a Static config (however a Static config requires editing other config-files as well). %0a%3c %0a%3c '''Note''': If you chose DHCP when first installing OpenBSD, then your hostname.if will probably contain just one line: '[@inet autoconf@]' or '[@dhcp@]' (which is just an alias for '[@inet autoconf@]'). IPV6 would use the (extra) line: '[@inet6 autoconf@]'. %0a%3c %0a%3c !!! Setting up Static Networking%0a%3c %0a%3c Inside /etc/hostname.if (where you replace if with your device), you should put something similar to the following lines:%0a%3c %0a%3c [@%0a%3c inet 192.168.1.2 255.255.255.0%0a%3c inet alias 192.168.1.3 255.255.255.0%0a%3c inet6 2001:0db8:0000:0000:0000:0000:0000:0000 48%0a%3c inet6 alias 2001:0db8:0000:0000:9b1d:3511:387e:143a 48%0a%3c inet6 alias 2001:0db8:0000:0000:1465:fed1:8daf:66ff 48%0a%3c inet6 alias 2001:0db8:0000:0000:11b4:4a36:2941:d6bd 48%0a%3c inet6 alias 2001:0db8:0000:0000:ad2c:5b99:2b1a:89d1 48%0a%3c inet6 alias 2001:0db8:0000:0000:921d:28ad:4729:8d93 48%0a%3c @]%0a%3c %0a%3c Note: Do '''not''' use those exact IP addresses. Use the real IP addresses you were assigned by your ISP.%0a%3c %0a%3c Let's look at the first two lines:%0a%3c %0a%3c [@%0a%3c inet 192.168.1.2 255.255.255.0%0a%3c inet alias 192.168.1.3 255.255.255.0%0a%3c @]%0a%3c %0a%3c The first line will set the device to use the static IP 192.168.1.2 with subnet mask 255.255.255.0. The second line will allow the device to use a second static IP, 192.168.1.3. It will be aliased to the first and have the same subnet mask.%0a%3c %0a%3c It makes sense to have an aliased IP address when two or more IP addresses share the exact same networking interface. You will see this being done if you have one normal IPv4 address and a DDoS filtered IPv4 address. Both of them actually share the same networking interface, so the unfiltered IPv4 address is actually an alias of the filtered one.%0a%3c %0a%3c Let's look at lines 3 and 4:%0a%3c %0a%3c [@%0a%3c inet6 2001:0db8:0000:0000:0000:0000:0000:0000 48%0a%3c inet6 alias 2001:0db8:0000:0000:9b1d:3511:387e:143a 48%0a%3c @]%0a%3c %0a%3c The first line sets the device to use the static IPv6 address 2001:0db8:: with a /48 subnet, and the second one creates another IPv6 address 2001:0db8:0000:0000:9b1d:3511:387e:143a with a /48 subnet, aliased to the first IPv6 address. Each time you need a new IPv6 address, just add a new aliased IPv6 address. In this way, you can create dozens of unique IPv6 addresses so that each user on a shell account or bouncer can get a unique IPv6 address.%0a%3c %0a%3c !! Default Gateway%0a%3c %0a%3c The default gateway is the router that your server is connected to. This is where all the IP packets from your server will immediately forward its packets to. The default gateway will be provided by your ISP.%0a%3c %0a%3c Since we disabled the DHCP client, we must also now manually config the default gateway.%0a%3c %0a%3c In the file /etc/mygate, you specify the default gateway:%0a%3c %0a%3c [@%0a%3c 192.168.1.1%0a%3c 2001:0db8:0000:0000::1%0a%3c @]%0a%3c %0a%3c You should have received the gateway addres(ses) from your provider. In the example above you see an IP4 and IP6 address.%0a%3c %0a%3c %0a%3c !! DNS Servers%0a%3c %0a%3c Unless you already specified your custom DNS servers or set up your own local DNS such as [[Unbound/configure | Unbound]], then your system now no longer knows what DNS server to query (since the DHCP-client is now disabled). %0a%3c %0a%3c In the file /etc/resolv.conf we add our nameservers, such as in the example below:%0a%3c %0a%3c [@%0a%3c lookup file bind%0a%3c nameserver 9.9.9.9%0a%3c @]%0a%3c %0a%3c The keyword '[@nameserver@]' is followed by the IP4/IP6 address of the DNS server that you want your system to use. As always, check the ([[https://man.openbsd.org/resolv.conf.5 | manpage]]) for additional options.%0a%3c %0a%3c '''Note''': '[@lookup@]' specifies which databases should be searched, and the order to do so. [@bind@] = Query a domain name server [@file@] = Search for entries in /etc/hosts.%0a%3c %0a%3c %0a%3c !! Restart Networking%0a%3c %0a%3c To restart networking, run:%0a%3c %0a%3c [@%0a%3c $ doas sh /etc/netstart%0a%3c @]%0a%3c %0a%3c If this doesn't properly reset the networking, you can do the following:%0a%3c %0a%3c '''WARNING''': This will definitely disconnect all network connections.%0a%3c %0a%3c [@%0a%3c $ doas ifconfig if0 down%0a%3c $ doas route flush%0a%3c $ doas sh /etc/netstart%0a%3c @]%0a%3c %0a%3c '''Note''': Make sure to replace if0 with your real device.%0a%3c %0a%3c '''HINT''': Obviously, if you do this over ssh, your network would go down after the first command, disallowing you from entering the commands to get the network back up. We put the commands on one line seperated by a semicolon to pass all three so that we may reconnect after the network is back up.%0a%3c %0a%3c [@%0a%3c $ doas ifconfig if0 down; doas route flush; doas sh /etc/netstart%0a%3c @]%0a%3c %0a%3c %0a%3c !! ifconfig%0a%3c %0a%3c You can add new IPv4 addresses on the fly, without rebooting, by using ifconfig:%0a%3c %0a%3c [@%0a%3c $ doas ifconfig if0 alias 192.168.1.3 255.255.255.0%0a%3c @]%0a%3c %0a%3c For IPv6:%0a%3c %0a%3c [@%0a%3c $ doas ifconfig if0 inet6 2001:0db8::/48%0a%3c @]%0a%3c %0a%3c To delete an IPv4 address:%0a%3c %0a%3c [@%0a%3c $ doas ifconfig if0 192.168.1.3 delete%0a%3c @]%0a%3c %0a%3c To delete the IPv6 address:%0a%3c %0a%3c [@%0a%3c $ doas ifconfig if0 inet6 2001:0db8::/48 delete%0a%3c @]%0a%3c %0a%3c Note: replace if0 with your specific interface, and replace the IP addresses and subnet masks.%0a%3c %0a%3c To test if an IP address is working, you can use [[openbsd/ping|ping]], [[openbsd/netcat|netcat]], and [[openbsd/traceroute|traceroute]].%0a
+host:1653281922=38.87.162.129