ifconfig interview questions
Top ifconfig frequently asked interview questions
ifconfig 1.2.3.4 mtu 1492
This will set MTU to 1492 for incoming, outgoing packets or both? I think it is only for incoming
Source: (StackOverflow)
I try to set variable which get interface ip-address from ifconfig and read it later. But when i execute a echo command, variable still empty. Please look at my code:
/usr/bin/bash -c "HOST_IPS=$(/usr/bin/ifconfig | /usr/bin/awk 'BEGIN {cnt=0} {if($0 ~ /inet / && cnt==1) {print $2} cnt++}'); echo $HOST_IPS"
But /bin/echo work fine with same command:
/usr/bin/bash -c "echo $(/usr/bin/ifconfig | /usr/bin/awk 'BEGIN {cnt=0} {if($0 ~ /inet / && cnt==1) {print $2} cnt++}')"
Source: (StackOverflow)
just a question for my understanding. on my mac when I use ifconfig
command on my mac I get the following interfaces:
- en0
- en1
- lo0
- fw0
- vment0
- vment1
I don't understand why there are so many. I understand that eth0 would be for LAN connections, and that en0 is the wireless connection. But macbook only has one airport..so why en1 as well? not sure what vments are for either.
Source: (StackOverflow)
I want to edit the bashrc file to have a simple function called "myip" to run. As you might guess, the function myip prints only my internal IP address of my machine.
The far as I got working, this is the script:
ifconfig en1 | awk '{ print $2}' | sort
Which got my this output:
10.0.0.12
options=1<PERFORMNUD>
flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST>
fe80::daa2:5eff:fe96:ba2f%en1
d8:a2:5e:96:ba:2f
autoselect
active
I'm working on Mac OS X.
How can I get this done?
Source: (StackOverflow)
I want to process the output of a process, say ifconfig. As you all know output of ifconfig is a list of lines containing inet addr:
mask: etc. But I want to extract the ip alone[from inet addr: field] and list it. is it possible with pipe command? like
ifconfig | What should be here?
I want the output of this command as list of inet addresses
(of different access points if present).
Source: (StackOverflow)
I try to use mobile browser testing with ionic. I'm connected in the same Wifi as my iPhone and checked my IP-Address with the following command: ifconfig |grep inet
. When I'm running ionic server with the command ionic serve
I'm not able to open my ionic app on my iPhone using my IP-Address and the specified port from ionic. Do I have to enable something else on my machine? I also tried different ports without any success.
Source: (StackOverflow)
I am looking for a command line solution that would return me the primary (first) IP address of the localhost, other than 127.0.0.1
The solution should work at least for Linux (Debian and RedHat) and OS X 10.7+
I am aware that ifconfig is available on both but it's output is not so consistent between these platforms.
Source: (StackOverflow)
I'm looking to use my eth0 ipv6 address in one of my shell scripts. I could retrieve it using ifconfig and grep, but I'm certain that it must be somewhere in some text file I'm not seeing, which would ultimately make it much easier to retrieve. Anyone know where I should look?
Thanks
Source: (StackOverflow)
Is there anyway to add and remove IP addresses from an interface (like loopback) in C?
I found ioctl and a few documents explaining how to do that (e.g. this link), however they are all for setting addresses not adding and removing?
Following the suggestions I ran strace for adding a new loopback and here is the results:
$ sudo strace ip addr add 1.2.3.4 dev lo
execve("/sbin/ip", ["ip", "addr", "add", "1.2.3.4", "dev", "lo"], [/* 17 vars */]) = 0
brk(0) = 0x1bab000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f221ed04000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=109414, ...}) = 0
mmap(NULL, 109414, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f221ece9000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\r\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14768, ...}) = 0
mmap(NULL, 2109704, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f221e8e0000
mprotect(0x7f221e8e2000, 2097152, PROT_NONE) = 0
mmap(0x7f221eae2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f221eae2000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200\30\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1811128, ...}) = 0
mmap(NULL, 3925208, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f221e521000
mprotect(0x7f221e6d6000, 2093056, PROT_NONE) = 0
mmap(0x7f221e8d5000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b4000) = 0x7f221e8d5000
mmap(0x7f221e8db000, 17624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f221e8db000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f221ece8000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f221ece7000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f221ece6000
arch_prctl(ARCH_SET_FS, 0x7f221ece7700) = 0
mprotect(0x7f221e8d5000, 16384, PROT_READ) = 0
mprotect(0x7f221eae2000, 4096, PROT_READ) = 0
mprotect(0x638000, 4096, PROT_READ) = 0
mprotect(0x7f221ed06000, 4096, PROT_READ) = 0
munmap(0x7f221ece9000, 109414) = 0
socket(PF_NETLINK, SOCK_RAW, 0) = 3
setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=6804, groups=00000000}, [12]) = 0
sendto(3, "\24\0\0\0\22\0\1\3\214;\367P\0\0\0\0\0\0\0\0", 20, 0, NULL, 0) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\344\3\0\0\20\0\2\0\214;\367P\224\32\0\0\0\0\4\3\1\0\0\0I\0\1\0\0\0\0\0"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 2000
brk(0) = 0x1bab000
brk(0x1bcc000) = 0x1bcc000
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0\214;\367P\224\32\0\0\0\0\0\0\1\0\0\0I\0\1\0\0\0\0\0"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 20
sendmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"(\0\0\0\24\0\5\6\215;\367P\0\0\0\0\2 \0\0\1\0\0\0\10\0\2\0\1\2\3\4"..., 40}], msg_controllen=0, msg_flags=0}, 0) = 40
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"$\0\0\0\2\0\0\0\215;\367P\224\32\0\0\0\0\0\0(\0\0\0\24\0\5\6\215;\367P"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 36
exit_group(0) = ?
Source: (StackOverflow)
Noobie at java just starting, would appreciate any help. So my code is this and for some reason I cant get the output to work..I ve been sitting at this for hours..
package askisi1;
import java.net.*;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
public static void main(String[] args){
try{
String command = "ifconfig eth1 | grep -oP '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}'";
Process child = Runtime.getRuntime().exec(command);
System.out.println("So far so good");
BufferedReader r = new BufferedReader(new InputStreamReader(child.getInputStream()));
String s;
while ((s = r.readLine()) != null) {
System.out.println(s);
}
r.close();
System.out.println("Continue..");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
Source: (StackOverflow)
Hi I am new to Expect scripting, and I have been trying to fetch an IP address into a variable using following :
set timeout -1
spawn $env(SHELL)
match_max 100000
send "ifconfig | grep -A 1 'eth1' | tail -1\r "
expect -re "inet addr:.* " {send "ping $expect_out(0,string)\r"}
send -- "exit\r"
expect eof
The problem is that it is trying to ping with the result of the ifconfig command which has some string characters in it.
Could anyone help me to extract just IP address from the ifconfig command and store it in a variable? I have been using $expect_out(buffer) as well, but just couldn't get my head around it. Any help along these lines would be much appreciated.
Source: (StackOverflow)
We added a second IP-Adress to a linux (debian) machine to implement a second SSL-certificate to a new Apache vhost.
Our ifconfig
now looks like this:
eth0 Link encap:Ethernet Hardware Adresse 00:0c:29:1b:ab:6c
inet Adresse:999.999.999.39 Bcast:999.999.999.63 Maske:255.255.255.192
inet6-Adresse: (...)/64 Gültigkeitsbereich:Verbindung
UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1
RX packets:219336884 errors:0 dropped:0 overruns:0 frame:0
TX packets:223169420 errors:0 dropped:0 overruns:0 carrier:0
Kollisionen:0 Sendewarteschlangenlänge:1000
RX bytes:1971307659 (1.8 GiB) TX bytes:713489565 (680.4 MiB)
eth0:1 Link encap:Ethernet Hardware Adresse (...)
inet Adresse:999.999.999.40 Bcast:999.999.999.63 Maske:255.255.255.192
UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1
Problem: All outgoing traffic (MySQL connections to external DB-server, outgoing SMTP connections from postfix) now seems to leave through eth0:1, hence the second (new) IP 999.999.999.40.
How can we force all outgoing traffic to leave through eth0, IP-adress 999.999.999.39?
Output of route:
[n1 ~ #] route
Kernel-IP-Routentabelle
Ziel Router Genmask Flags Metric Ref Use Iface
localnet * 255.255.255.192 U 0 0 0 eth0
10.10.10.0 * 255.255.255.0 U 0 0 0 eth1
default gateway4.XXX 0.0.0.0 UG 0 0 0 eth0
default gateway4.XXX 0.0.0.0 UG 0 0 0 eth0
Found solution:
Thanks for your hints, ip route
was the way to go, now it works as desired.
ip rule add from 999.999.999.39 table t1
ip rule add from 999.999.999.40 table t2
ip route del default via 999.999.999.1
ip route add default 999.999.999.1 dev eth0 table t1
ip route flush cache
Source: (StackOverflow)
I am trying to get the following formatted output out of ifconfig:
en0: 10.52.30.105
en1: 10.52.164.63
I've been able to at least figure out how to get just the IP addresses (weeding out localhost) with the following command, but it's not sufficient for my requirements:
ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'
Thanks!
Source: (StackOverflow)
I can run this command fine, with the output I want:
ifconfig eth0 | grep HWaddr | awk '{print $5}'
However, when I set the command to a variable, and print the variable, I get an error:
CASS_INTERNAL=`ifconfig eth0 | grep HWaddr | awk '{print \$5}'`
$CASS_INTERNAL
my internal xxx ip: command not found
The weird thing - my internal IP actually shows up. How do I go about this without getting an error? It shouldn't matter, but I'm using the latest version of Ubuntu.
Source: (StackOverflow)