Can ping hostname linux

Ubuntu can not ping Host Name but can ping IP?

How is it that I can only ping by IP address and not by hostname to the windows computers? But Ubuntu can ping itself by IP address and Hostname and windows computers can ping Ubuntu by hostname as well?

Yeah, I tried that, but no luck. =( Someone said to add .local at the end. My co workers said I have to configure the network to point at the router in order for it to understand. So I will try that out, and if it works, I’ll go ahead and post the answer

It may be a DNS server problem. Configure DNS server settings correctly. Maybe these two sources can help you. serverfault.com/questions/389522/…. askubuntu.com/questions/23011/….

2 Answers 2

The problem described here may not be related to DNS at all.

You have to know that Windows can resolve the Windows hostname to its IP via other mechanisms than standard DNS : NetBIOS lookup, WINS, .

As you said you have Samba installed on your Ubuntu, this is probably what’s happening. On all of your Windows machine, it is possible, out-of-the-box, to have the Windows name resolved to its IP address. As Samba is installed on Ubunut, for your Windows PC, they see the Ubuntu PC as a Windows PC and the same resolution is possible.

You tell that you run net view on Windows and you see your Ubuntu PC, so the NetBIOS name is well published on your network, so it works from Windows.

To achieve the same behaviour on Ubuntu as on Windows, you have to install and configure additional pieces of software. What you need is to add a lookup library that will allows Ubuntu to convert NetBIOS names to IP. This library is contained into the libnss-winbind package.

As any other Ubuntu packages, you install it by doing sudo apt-get install libnss-winbind . May be the library is already installed, you can check it presence by doing dpkg -l|grep libnss-winbind .

Once the library is installed, you have to enable it in the /etc/nsswitch.conf file. This file is the configuration file for the NSS (Name Service Switch), which defines from which sources Linux is able to resolve hostname, usernames, groupnames and so on.
In this file, you already have a line starting by hosts: , probably looking like this

This tells your system to first look into the /etc/hosts file and then into the configured DNS to resolve hostnames.
You have to modify this way :

Note that the order of the words files, dns and wins are important. First, the system will check the local file for resolution, then will ask the DNS server and finally, if not yet found, will perform NetBIOS lookup.

Читайте также:  Virtualbox разрешение экрана kali linux

Once this is updated, to function correctly, you also need to have the winbind service running. The package containing it is a dependency of libnss-winbind, so it has been installed along it.
Do service winbind start to activate it.

Источник

The Linux Ping Command

The Linux Ping Command

Ping or Packet Internet Groper is a network management utility that can check the connection status between a source and destination computer/device over an IP network. It also helps you estimate the time it takes to send and receive a response from the network.

We all have our favorite websites that we visit frequently; if one of them doesn’t load, we really want to know why. Is it because we don’t have an Internet connection, or is it problems with our Internet service provider that are preventing us from accessing the website? Another reason could be the unavailability of the website itself. Whatever the reason, the Linux Ping command can give you all the answers.

Ping uses the Internet Control Message Protocol (ICMP) to send and receive echo messages to and from the host or target computers to keep us informed of network performance. An ICMP request message is sent to the target computer; if the target IP address is available, it sends an ICMP message response to the host computer. This informs us about the connectivity status of the network, such as the round-trip time – the time it takes to send and receive an information packet.

Using the Ping command

In the Linux terminal type the following command:

This is the output you will get:

Linux ping command

Let us describe(in alphabetic order) the commonly used options that you can see above:

Option Description
a Use this option for a beep sound when the peer is reachable
b Use this option to allow pinging a broadcast address
B Use this option if you do not want to allow the ping to change the source address of the probe
c (count) Use this option to set the number of times to send the ping request
d Use this option to set the SO-DEBUG option on the socket being used
f Use this option to flood the network by sending hundred or more packets per second
i (interval) Use this option to specify an interval between successive packet transmissions. The default value of interval is 1 second
I (interface address) Use this option to set source address to the specified interface address. This option is required when pinging IPv6 link local address. Its argument can be an IP address or name of the device.
l (preload) Use this option to set the number of packets to send without waiting for a reply. For selecting a value more than 3, you need to be a super user.
n Use this option to display network addresses as numbers rather than as hostnames
q Use this option to display a quiet output. It means that only the summary is displayed at startup and finish time
T (ttl) Use this option to set the Time To Live
v Use this option for verbose output
V Use this option to display the version and exit
w (deadline) Use this option to specify a timeout, in seconds, before ping exits, regardless of how many packets have been sent or received.
W (timeout) Use this option to set the time(seconds) to wait for a response
Читайте также:  Linux source code editors

Some Basic Ping functions

Here are some basic ping functions that you will be used to check the performance of your network:

Pinging the host for availability

You can check if a host is alive or not through the following ping command:

Press Ctrl+C for breaking the command

Pinging the host for availability

Increase/Decrease interval between ping packets

The default time interval between sending each packet is 1 second in Linux. You can increase the time interval by setting a value greater than 1 and decrease it by setting a value less than 1.

Here is an example to increase the time interval between two pings:

Here is an example to decrease the time interval between two pings:

As you can see in the following image, you need to be a superuser in order to set this time interval lesser than 0.2 seconds:

Increasing/Decreasing interval between ping packets

Therefore, the command should be executed with sudo. It should look like the following,

Enter the password when you are prompted and the command should work.

Change ping packet size

The default ping packet size is 56 bytes. You can change it through the following command:

$ ping -s packetsize hostname/IP

Here we are setting the packet size to 100; you can see the value set to 100 in the first line of output:

Change ping packet size

Set ping to send a desired number of packets

You can set ping to send a desired number of packets as follows:

$ ping -c NumberOfPackets IP/hostname

In the following example, we are setting the number of packets as 5; after that, the results will end:

Set ping to send a desired number of packets

Flooding the network

Ping command allows super users to send 100 or more packets per second through the following command:

Flooding the network

Ping prints a “.” when sending a ping and “/” when receiving one.

Set ping timeout

You can set a time limit after which ping will exit; no matter how many ping packets are sent or received:

$ ping -w timeinseconds hostname/ip

Here we are using 3 seconds as timeout:

Set ping timeout

Audible ping

The ping command can be set to play a beep to check whether the host is available as follows:

Practicing around with this tutorial will enable you to run ping commands to check your network performance in an optimal way. You can also use advanced switches to customize your requests and responses in ping.

About This Site

Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.

Latest Tutorials

Источник

my linux pc not pingable using hostname

From a remote machine I am able to ping my computer by its IP address, but not by its hostname. How can I make it accessible by its hostname as well?

Just to clarify: you can ping your PC (from a different machine) via its IP, and fail doing so with using its hostname?

I just don’t get you 100%: say your IP is 1.2.3.4 and the hostname is linuxmachine . Then ping 1.2.3.4 works and ping linuxmachine fails. Is that the problem?

Читайте также:  Jetbrains trial reset linux

2 Answers 2

If I understand your problem correctly, you want to ping your computer from another computer. The ping 1.2.3.4 works but the ping hostname doesn’t. What I suspect the situation being is that your computer doesn’t have a its hostname registered in DNS that is discoverable by the other machine.

If the hostname is not known to the other machine it does not know where to send the ping.

other computer ping 1.2.3.4 -> your computer

other computer ping hostname -> unknown

you should set the other computer’s hosts file so that it knows what hostname means. The hosts file is at /etc/hosts and needs to be edited while root. What you need to enter there is 1.2.3.4 hostname , you can do this with command

# echo «1.2.3.4 hostname» >> /etc/hosts

and of course this needs to be entered in the other computer’s hosts file.

If the two computers are connected to the same router you may edit the routers hosts the same way and then all the computers in the same network know each other by name. This is assuming that all the computers use the router as their DNS server. You may get more info of the DNS from wikipedia

Источник

Can’t ping to another linux machine by hostname

When i try to ping to another linux machine in my local network i didn’t work when i insert the host-name in the ping command.

That is a possibility but because we do this in school we can’t use a fixed IP address it changes every week

4 Answers 4

TL;DR

If you can’t control the both the DHCP server and the name lookup service for your network, you’re limited in what you can do. Typical options are /etc/hosts and a dynamic DNS service, but if you don’t have root on either box then you’ll just have to use the IP address directly.

Resolving Names

You can’t look up a host by name unless you are able to resolve it. The Debian manual explains:

8.3.1. Name Resolution The mechanism for name resolution in Linux is modular and can use various sources of information declared in the /etc/nsswitch.conf file. The entry that involves host name resolution is hosts. By default, it contains files dns , which means that the system consults the /etc/hosts file first, then DNS servers. NIS/NIS+ or LDAP servers are other possible sources.

Since your comment says the target host has a dynamic IP address, if Raspberry2 doesn’t update DNS (or one of the other data sources) when it gets its IP address, then you have to resolve it through a static entry in your /etc/hosts file or simply pass an IP address as you already do.

If your Raspberry Pi device is inside a private network, and if you can install the necessary software on it, a dynamic DNS service may still help if the client supports looking up the IP assigned to the host’s network interface, rather than just a publicly-resolvable IP address. Your mileage with dynamic DNS will most definitely vary.

Источник

Оцените статью
Adblock
detector