I need all name servers (DNS) in linux - linux

If there are multiple NICs on a machine, and each NIC is configured for multiple name servers, I need a list of all of them.
I have written simple java code to parse ipconfig /all in Windows (I need this in java), but getting the same information in Linux seems unclear from researching.
Some articles say "cat /etc/resolv.conf". Some say that is the old way for some distributions and to use nmcli with appropriate arguments and just parse the information.
My research has led me to believe the following is how it probably should be done:
Check of nmcli is available
Check if network-manager is on
if so, parse nmcli output
if not, parse cat /etc/resolv.conf
I am not an expert in linux, so I am seeking validation or correction here.
Thanks for answering!
EDIT: If it helps, I care about RHEL6+ and Suse 11
EDIT2: So per Suse's documentation, parsing resolv.conf seems to be sufficient because they just update the file. Still looking into RHEL.

Looks like reading resolv.conf is a safe bet for the current releases of RHEL and Suse.

Related

/etc/hosts ignored in mac El Capitan (10.11.5)

I'm attempting to redirect an existing web address to a remote machine on my subnet. To do that, I put the following into /etc/hosts
192.168.1.249 holub.com
and flush the DNS cache with
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder
However, when I ping holub.com (the most reliable way that I know to see how the address is actually resolved), I see the real web address (204.13.10.74), not the one specified in /etc/hosts (192.168.1.249). Interestingly, the mysqladmin utility does not resolve the address correctly, but the Chrome browser does resolve the address correctly. I'm guessing that Chrome has some sort of internal workaround.
In general, it looks like /etc/hosts is being used after the actual DNS lookup, not before as it should be, so an external address is not overridable.
I've tried using various IPv6 equivalents to my local address (0:0:0:0:0:ffff:c0a8:01f9 ::ffff:192.168.1.249 ::192.168.1.249), but that doesn't help. Rebooting (instead of flushing the cache) doesn't help either.
I have found one unsatisfactory workaround. If I disable the DNS reponder with
sudo launchctl unload -w
/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
then /etc/hosts is used, but then I can't access the internet.
If anybody's encountered this problem, I'd love to know if there's a workaround.
I came across this while searching for an answer to a similar problem and wanted to post my findings for anyone else in the same position.
As a team of three, we found that edits to my /etc/hosts file appeared to work, while editing the other two's host files seemingly did not. Upon further digging, we realized I was on OS X 10.10, while they were on newer versions.
We found, after trying about a million things, that additions to the hosts file in 10.11 and up apparently could not have more than one space between the IP and the domain, for example:
DID NOT WORK:
1.2.3.4 some.site.com
DID WORK:
1.2.3.4 some.site.com
After making this change, we immediately started seeing expected results without any cache clears, reboots, or otherwise.
I know in your example you are only showing one space, but in the off chance that's now how it appeared in your actual file I wanted to share this anyway.

How can I make Ubuntu successfully search for an environment variable for licenses?

I have Ubuntu 10.04, 10.10, and 11.10 in virtual machines on oracles virtual box that I am testing products on. The licenses for the software to run is on my machine which is assigned a static IP.
SO what I have done for all the other Linux distributions I have done testing with is assign the .bashrc file a line in the end like this: export LICENCE=27065#192.168.1.45 causing it to look in the network for my machine to check out and check in its licenses. I have done the same with Ubuntu but cant get it to work at all! So far Ubuntu seems to be the only one with this problem.
SO i figured that maybe it was a connectivity issue. perhaps some behind the scenes security factor that i didn't know about. Well turns out I can ping my machine on the network just fine which makes me a little more lost.
Any info on this or even some more troubleshooting tips would be greatly appreciated.
Is this a FlexLM license? It looks like it because of the port#hostname string.
LICENCE looks wrong, these products usually use LM_LICENSE_FILE or *$PRODUCTNAME*_LICENSE_FILE, see eg. http://opendtect.org/lic/endusermanual/chap12.htm
Check with telnet if this host/port is available: telnet 192.168.1.45 27065. It's possible that ping works but connecting to this specific port doesn't.
Depending on how you start the shell in, .bashrc is not used, do you see it when you echo the variable? If not, stick it in .bash_profile instead
Try setting FLEXLM_DIAGNOSTICS=3 as described in the link above.

How to get Network Statistics of a Remote PC

H!
I have to make an application in vc++ which can get the network statics of remote PC.
Is any one can help me to solve my problem?
Since you said vc++, therefore, I assume that you have to do this in Windows environment. Have a look at SNMP protocol. And How it can be used to get information of remote machines.
Look at this SO Question as well.
Depending on the network statistics that you want to capture, you may find that (as Aamir suggested) SNMP is a good choice.
There are standard MIBs defined that will provide a number of network statistics. Three that are worth investigation are:
IF-MIB,
RMON, and
Etherlike MIB
NET-SNMP is a good library for accessing SNMP information and is available for Windows (as you've mentioned vc++). Others are available.
This does assume that you have an SNMP agent running and accessible on the remote machines that you wish to monitor.

JMeter - Loopback address error when launching jmeter-server on Linux

I'm trying to set up a distributed load testing environment using JMeter. I need to set up the remote clients using something portable like a Linux Live CD, but whenever I attempt to launch jmeter-server in Linux, I receive the following error...
Created remote object: UnicastServerRef [liveRef: [endpoint:[127.0.0.1:49018](local),objID:[3b0d3d42:12985b7a49b:-7fff, -8459389540436649718]]]
Server failed to start: java.rmi.RemoteException: Cannot start. testbox01.qa.nwr.lan is a loopback address.
After extensive googling, the only remedy I can find is to edit the /etc/hosts file so the hostname maps to something other than the 127.0.0.1 loopback address. I've tried this using Ubuntu, Fedora and CentOS, and apparently they all default to setting the hostname to 127.0.0.l.
The way I see it, I have four options...
1) Customize the /etc/hosts file for every remote test box I set up, which involves upwards of 20-50 dynamically DHCP-assigned IP addresses.
2) Figure out a way to force Linux itself to assign the hostname to its DHCP IP address by default. This is certainly the more graceful solution, but I have no idea how to do this. Anyone know?
3) Find and use a Linux distro available as a Live CD that doesn't map its hostname to 127.0.0.1 by default. Anyone know one?
4) Dive into JMeter's code and start yanking wires, but if it comes to this, I'd just as soon use another open source tool with a slimmer feature set, but whose distributed architecture doesn't suffer from this issue.
If anyone has any advice, I'd be grateful. Thanks!
In latest version, you can run your script with:
./jmeter-server -Djava.rmi.server.hostname=xxx.xxx.xxx.xxx
Replace xxx.xxx.xxx.xxx with this server's IP address, i.e., the IP address that the controlling jmeter machine will use to connect to this server.
Looks like Glen was right on the money with his comment.
Not sure is this helps but I found a bug which seems to contain a patch for this issue.
https://bugs.launchpad.net/ubuntu/+source/jakarta-jmeter/+bug/589042
Thanks again, Glen!
(If you decide to make it into an actual answer, I'll be sure to accept it!)
Change your hostname from localhost to your right ip address.
Check your hostname
hostname
Check your internet ip address
ifconfig
Add this line to /etc/hosts
your_ip_address your_hostname
Comment hostname which assigned localhost in /etc/hosts
I was able to get it to start after setting this environment variable:
export RMI_HOST_DEF=-Djava.rmi.server.hostname=XXX.XXX.XXX.XXX
Also have downloaded jmeter 2.8 from here: http://archive.apache.org/dist/jmeter/binaries/
Ubuntu apt-get version is 2.3.4
You can edit jmeter.server file to add:
RMI_HOST_DEF=-Djava.rmi.server.hostname=XXX.XXX.XXX.XXX
This solved mine problem.
You can try to check this page for more details.
Add RMI_HOST_DEF=-Djava.rmi.server.hostname=XXX.XXX.XXX.XXX
Add ipaddress hostname to /etc/hosts file
on my system ,/etc/hosts mentioned 127.0.0.1 hostname.
I removed 127.0.0.1 and added public Ip address

Doing ARP and Inverse ARP on Linux 2.6.21 (glibc 2.3.5)

I need to store persistent reference to third party device on an arbitrary IP network where the IP address of the devices may be static or randomly assigned by DHCP. I don't control the devices on the network and I can't rely on DNS and other ad-hoc networking protocols existing or working with the devices.
So I have been instructed to investigate using hardware addresses and ARP. This will work but I don't want to duplicate code. The kernel must manage an ARP table. On Windows you can access it using GetIpNetTable etc.
I am hoping there is an API to answer these two questions:
How do I translate from IP to MAC address? (ARP)
How do I translate from MAC to IP address? (InARP)
If not then I may have to do it more manually:
How do I read the kernel's ARP table?
How do I add an entry if I have the determined a mapping myself?
/proc/net/arp
K
ARP tables tend to be fairly local and short-lived. If you examine the protocol, the real MAC addresses are generally only provided when the given IP address is in the local subnet.
Otherwise, the packet is forwarded to the local router, which is then responsible for forwarding it.
If you do "arp -g" on Windows or "arp -a" on UNIX, you'll see the table, but I don't think it will do you any good, due to the reasons mentioned above. That command and
That's really what DNS is for but, as you say, it may not be an option for you.
You may well have to write your own 'ARP' database at your application level.
As for ARP:
You could use system("/usr/bin/arp -option_of_choice"); and parse the output, but that's an ugly hack. -- Not my recommendation.
Take a look at /usr/include/linux/sockios.h -- At the SIOCGARP, SIOCDARP, and SIOCSARP details. Those are ioctls that you can perform to manage the ARP table on linux. Of course, you'll have to perform these ioctls on a socket fd.
Here's some examples: SIOCGARP examples
I'm sure you can find many other examples in several other languages as well. As I'm assuming that you're using C.
As for RARP:
A quote from the linux rarp manpage:
" This program is obsolete. From version 2.3, the Linux kernel no longer
contains RARP support. For a replacement RARP daemon, see ftp://ftp.demen-
tia.org/pub/net-tools"
So you'll have to install rarpd on the target system.

Resources