Sponsored Content
Top Forums Shell Programming and Scripting Bash- Determine what interface is online Post 302852785 by Corona688 on Thursday 12th of September 2013 12:08:16 PM
Old 09-12-2013
Which interface is connected to the internet is a routing thing:

Code:
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.0.2      0.0.0.0         255.255.255.255 UH    0      0        0 tun0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 lan
172.16.0.0      172.16.0.2      255.255.0.0     UG    0      0        0 tun0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 lan

So, to always grab the catch-all default gateway:

Code:
$ /sbin/route -n | awk '/0\.0\.0\.0/ && /UG/ { print $NF ; exit }'

lan

$

 

8 More Discussions You Might Find Interesting

1. Programming

determine if a ethernet interface is up

Howto check if a ethernet interface is up? It's impossible to determine via the ipaddress i have learned, or? Can someone please give me a hint on howto do? Environment == Linux x86 GNU GCC. :D regards Esaia (2 Replies)
Discussion started by: Esaia
2 Replies

2. IP Networking

How to determine the interface?

Given the interfaces on a firewall: eth0 Link encap:Ethernet HWaddr 02:40:67:34:F5:47 inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 eth1 Link encap:Ethernet HWaddr 86:23:98:45:35:56 inet addr:123.45.240.69 Bcast:255.255.255.255 ... (2 Replies)
Discussion started by: kikikaka
2 Replies

3. UNIX for Advanced & Expert Users

command for CPU online/offline status in bash shell

Hi , How do i check that the CPU is online/offline in a multi CPU machine in Linux ? i tired /proc/cpuinfo dmesg nothing gave me the currect CPU status. Pls help !! (5 Replies)
Discussion started by: sars
5 Replies

4. Solaris

Determine Solaris box network interface?

Given a new Solaris box, with a fresh, unconfigured install on it, how does one figure out what kind of network interface it has (bge,le, hme, etc)? (8 Replies)
Discussion started by: akbar
8 Replies

5. HP-UX

How to determine network interface that will be used to send a packet for an IP

Hello, I'm writing to you because I encountered the following problem. My program displayes all network interfaces that are available in the system, but I would like to add a functionality in which a user can enter a destination address IP (ex. the IP address of the Google search engine) and will... (1 Reply)
Discussion started by: foxrafi
1 Replies

6. SCO

Change SCO - GUI or Desktop interface to DOS based interface

Hi all I have installed a demo version of SCO OpenServer 5.0.2, I finally found it is Desktop Interface, I would like to know how to change its interface to dos based interface? If you have any ideas, please tell me then. Thank you (2 Replies)
Discussion started by: TinhNhi
2 Replies

7. Shell Programming and Scripting

How to define a variable in a BASH script by using a JSON file online?

Hello, I would like to modify an existing script of mine that uses a manually defined "MCVERSION" variable and make it define that variable instead based on this JSON file stored online: https://s3.amazonaws.com/Minecraft.Download/versions/versions.json Within that JSON, I 'm looking for... (4 Replies)
Discussion started by: nbsparks
4 Replies

8. Solaris

Determine PCI Endpoint for a Serial Interface.

Hi Folks, Here is one for the real Solaris aficionados on the site; I have a T5240 and have to create an I/O domain with access to the serial port, in this case /dev/term/a and although I have been through the documentation I'm having some issues in identifying the device to assign. What I... (2 Replies)
Discussion started by: gull04
2 Replies
SYSTEMD-NETWORKD-WAIT-ONLINE.SERVICE(8) 		     systemd-networkd.service			   SYSTEMD-NETWORKD-WAIT-ONLINE.SERVICE(8)

NAME
systemd-networkd-wait-online.service, systemd-networkd-wait-online - Wait for network to come online SYNOPSIS
systemd-networkd-wait-online.service /lib/systemd/systemd-networkd-wait-online DESCRIPTION
systemd-networkd-wait-online is a one-shot system service that waits for the network to be configured. By default, it will wait for all links it is aware of and which are managed by systemd-networkd.service(8) to be fully configured or failed, and for at least one link to gain a carrier. OPTIONS
The following options are understood: -i, --interface= Network interface to wait for before deciding if the system is online. This is useful when a system has several interfaces which will be configured, but a particular one is necessary to access some network resources. This option may be used more than once to wait for multiple network interfaces. When used, all other interfaces are ignored. --ignore= Network interfaces to be ignored when deciding if the system is online. By default, only the loopback interface is ignored. This option may be used more than once to ignore multiple network interfaces. --timeout= Fail the service if the network is not online by the time the timeout elapses. A timeout of 0 disables the timeout. Defaults to 120 seconds. SEE ALSO
systemd(1), systemd-networkd.service(8) systemd 237 SYSTEMD-NETWORKD-WAIT-ONLINE.SERVICE(8)
All times are GMT -4. The time now is 11:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy