OpenBSD Set / Change Default Gateway

Q. How do I change or set a default gateway under OpenBSD operating system?

A. You need to add / edit /etc/mygate file which contains the address of the gateway host / router. The gateway is added to the routing tables by the route utility while booting the system.

ADVERTISEMENTS

The file may contain gateway addresses for both IPv4 and IPv6 networks: in dotted quad notation for IPv4 (e.g. 192.168.1.254) or in colon notation for IPv6 (e.g. 2001:1234:5678::1). Each address must be specified on a separate line (new line). If more than one address of a specific family is found, only the first is used – all other addresses of that family are ignored.

/etc/mygate is processed after all interfaces have been configured. If any hostname.iface files contain dhcp directives, IPv4 entries in /etc/mygate will be ignored. If they contain rtsol directives, IPv6 entries will be ignored.

View Current Routing Table

Type the following commands to view current routing table:
# route show
# route -n show
# netstat -r

Change or Add Gateway IP address

Open /etc/mygate file:
# vi /etc/mygate
Append / modify new IP:
192.168.1.254
Save and close the file.

Add route from a command prompt

Adding routes is very simple with the “route add” command. All you need to know is the network block you want to route, the netmask for that block, and the IP address you want them routed to:
# route add 192.168.1.0 -netmask 255.255.255.0 192.168.1.254

OpenBSD delete Route

Type the following command:
# route delete 192.168.1.0 -netmask 255.255.255.0

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • me here Sep 27, 2012 @ 0:03

    Thank you. This page really helps me and easy to follow howto.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.