OpenBSD Change, Add or Display Default Gateway

How do I change existing openbsd gateway (openbsd routing) IP address? How do I see current routing table under OpenBSD?

OpenBSD uses a special file to store default gateway in /etc/mygate file. You need to put the IP of your gateway in the file /etc/mygate. This will allow your gateway to be set upon boot. The gateway is added to the routing tables by the route utility. If /etc/mygate does not exist, no default gateway is added to the routing tables. The file may contain gateway addresses for both IPv4 and IPv6 networks: in dotted quad notation for v4 (e.g. 192.0.2.0) or in colon notation for v6 (e.g. 2001:1234:5678::1). Each address must be specified on a separate 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.

Task: Display default gateway

Type the following command
$ cat /etc/mygate
Output:

75.126.68.49

75.126.68.49 is the router IP address.

You can also type any one of the following command to display router IP address:
$ route show
OR
$ netstat -rn
Output:

Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use    Mtu  Interface
default            75.126.68.49       UGS         7     1203      -   pcn0
75.126.68.48/29    link#1             UC          1        0      -   pcn0
75.126.68.49       00:15:c7:32:a0:00  UHLc        1        0      -   pcn0
127/8              127.0.0.1          UGRS        0        0  33192   lo0
127.0.0.1          127.0.0.1          UH          1        0  33192   lo0
224/4              127.0.0.1          URS         0        0  33192   lo0

Internet6:
Destination                        Gateway                        Flags    Refs      Use    Mtu  Interface
::/104                             ::1                            UGRS        0        0      -   lo0
::/96                              ::1                            UGRS        0        0      -   lo0
::1                                ::1                            UH         12        0  33192   lo0
::127.0.0.0/104                    ::1                            UGRS        0        0      -   lo0
::224.0.0.0/100                    ::1                            UGRS        0        0      -   lo0
::255.0.0.0/104                    ::1                            UGRS        0        0      -   lo0
::ffff:0.0.0.0/96                  ::1                            UGRS        0        0      -   lo0
2002::/24                          ::1                            UGRS        0        0      -   lo0
2002:7f00::/24                     ::1                            UGRS        0        0      -   lo0
2002:e000::/20                     ::1                            UGRS        0        0      -   lo0
2002:ff00::/24                     ::1                            UGRS        0        0      -   lo0
fe80::/10                          ::1                            UGRS        0        0      -   lo0
fe80::%pcn0/64                     link#1                         UC          0        0      -   pcn0
fe80::20c:29ff:fe7b:6672%pcn0      00:0c:29:7b:66:72              UHL         0        0      -   lo0
fe80::%lo0/64                      fe80::1%lo0                    U           0        0      -   lo0
fe80::1%lo0                        link#5                         UHL         0        0      -   lo0
fec0::/10                          ::1                            UGRS        0        0      -   lo0
ff01::/32                          ::1                            UC          0        0      -   lo0
ff02::%pcn0/32                     link#1                         UC          0        0      -   pcn0
ff02::%lo0/32                      ::1                            UC          0        0      -   lo0

Task: Update or change OpenBSD default gateway

Open /etc/mygate file using a text editor such as vi, enter:
# vi /etc/mygate
Remove existing IP and put the new IP address:
75.126.68.100
Save and close the file. To activate the changes type the following command:
# sh /etc/netstart


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig 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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
1 comment… add one
  • Brent Jan 11, 2011 @ 14:23

    Hiya

    Its actually /etc/mygate not /etc/mygat.

    HTH
    Brent

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum