Linux all server list

How can I list all vhosts in nginx

Is there a command that will list all vhosts or servers running under nginx on CentOS? I would like to pipe the results to a text file for reporting purposes. I’m looking for something similar to this command that I use for Apache: apachectl -S 2>&1 | grep ‘port 80’

That depends on what you call vhost . Nginx’s server block could match any number of domains. Maybe you want to list all server blocks?

Yes, server blocks would work. Probably those for port 80. The point is to list all websites in order to generate billing for hosting.

8 Answers 8

starting from version 1.9.2 you can do:

show complete nginx configuration

nginx -T | grep "server_name " #include the whitespace to exclude non relevant results 

show you all server names

Much better answer, doesn’t assume config directory structure, only shows what nginx is aware of. Thanks

Yap! That should be the green checked answer. Right in the context of the question. People tent to curry away some times!!

This needs the green tick. And can be modified to include the current answer for lower Nginx versions.

Note that you may need to pass -p also (e.g. on GitLab Omnibus: /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx -T )

Update: Thanks to @Putnik for pointing out an easier way (but I prefer only listing sites-enabled):

grep server_name /etc/nginx/sites-enabled/* -RiI 
find /etc/nginx/sites-enabled/ -type f -print0 | xargs -0 egrep '^(\s|\t)*server_name' 

If you’re hosting thousands of websites, chances are that some of your confs will have multiple domains separated by newlines. This answer will not capture those. See the answer below by Anthony Briggs which is the most complete.

To my knowledge /etc/nginx/sites-enabled/ is created on Debian based systems (to mimic Apache). This is an elegant solution but not generic enough

The answers so far will work, except if you have server_name directives running over multiple lines, then it’ll silently fail. They also seem to be written for human consumption (picking up extra lines like server_name_in_redirect off; ) so you can’t include them in a script.

I have lots of virtual hosts, and wanted to use the output in a script (sigh), so here’s something which is a lot longer, but should be robust enough for that purpose:

nginx -T | sed -r -e 's/[ \t]*$//' -e 's/^[ \t]*//' -e 's/^#.*$//' -e 's/[ \t]*#.*$//' -e '/^$/d' | \ sed -e ':a;N;$!ba;s/\([^;\]\)\n/\1 /g' | \ grep -P 'server_name[ \t]' | grep -v '\$' | grep '\.' | \ sed -r -e 's/(\S)[ \t]+(\S)/\1\n\2/g' -e 's/[\t ]//g' -e 's/;//' -e 's/server_name//' | \ sort | uniq | xargs -L1 

Since it’s long and \ -y, I’ll include a quick explanation of each line.

  1. Get nginx to print its entire configuration (so that we don’t have to worry about which files to include) and sanitise it: remove leading and trailing space, comments (including trailing ones) and blank lines.
  2. Every line that doesn’t end with a semi-colon or curly brace should be continued, so we replace any \n without a preceding ; , < or >with a space. This needs to use sed’s weirdo :a;N;$!ba; grab the whole file trick, and some grouping so that we can put the last character back with \1 , plus a bunch of extra backslashes for luck.
  3. Now we can pull each server_name line, with some extra checks to remove nginx variables ( $foo ) and only include valid domains (ie not localhost and _ ).
  4. Any tabs/spaces between words get turned into carriage returns, then we remove surplus spaces (just in case), semi-colons and the server_name part.
  5. Finally sort it, uniqify it and use xargs -L1 to remove the single blank line at the top.
Читайте также:  Linux what are debugging symbols

Note that there are some bits in here which are technically doubling up, but I like to be as clear and robust as possible. Suggestions for improvement welcome, though.

Источник

Command-line to list DNS servers used by my system

But it doesn’t list any servers, if I go to «Network Manager GUI Tool», in Wireless section it lists «DNS 192.168.1.1 8.8.8.8 8.8.4.4» Can I get same information from command line? I am using Ubuntu 12.04 LTS

What are you trying to find? the DNS servers being used by your system? or are you trying to do a DNS lookup?

13 Answers 13

resolv.conf isn’t really used anymore, unless you implement it yourself. The network manager does it now. I created an alias to list the DNS servers on my system, as I sometimes switch from OpenDNS to Google’s open DNS.

nmcli device show | grep IP4.DNS 
nmcli dev list iface | grep IP4 

In my case, is eth0 , which is common, but not always the case. You can see your interfaces with

See if this is what you want.

I think resolv.conf is actually used indirectly, because the network manager creates the server that listens on 127.0.0.1, but I was told that this is an implementation detail that should not be counted on. I think that if you enter DNS addresses before this entry, they might get used, but I’m not sure exactly how this works. I think it’s best to use the network manager in most cases, when possible.

thanks, yes that seems to be working, ubuntu networking seems to be confusing, so I can set dns servers in resolve.conf/base or in /etc/network/interfaces or in network manager, is there a definitive guide for ubuntu networking?

@vcardillo: the original question stated: «I am using Ubuntu 12.04 LTS». It’s been 5 years since I posted my answer. Nothing lasts forever.

I would like to warn readers that the information provided by nmcli and nm-tool might not be correct. In testing my router setup, I changed the DHCP server to configure a DNS. On my client (linux mint 17.3) I did sudo dhclient -r; sudo dhclient to renew IP configuration. At this point both commands I mentioned showed the old DNS, not the new one. cat /etc/resolv.conf did work for me, but according to op it did not work for him. The only reliable way to figure out which DNS is used appears to be to a lookup with for example dig, but I doubt dig will show you all configured DNS.

Читайте также:  Kali linux virtualbox kernel panic

In Ubuntu 18.04 and 20.04 you can use systemd-resolve —status . In newer versions use resolvectl status .

IMO this should be the accepted answer. Also, it’s worth pointing out that systemd-resolve mydomain.com outputs which DNS server exactly is being queried (very useful if e.g. you have set up a VPN and so on).

This is valid for Ubuntu 13.10 and earlier. For Ubuntu 14.04 and above, see Koala Yeung’s answer to: How to know what DNS am I using in Ubuntu from 14.04 onwards

You will get an output similar to

NetworkManager Tool State: connected (global) - Device: eth0 [Wired connection 1] ------------------------------------------- Type: Wired Driver: e1000e State: connected Default: yes HW Address: 00:11:22:33:44:55 Capabilities: Carrier Detect: yes Speed: 1000 Mb/s Wired Properties Carrier: on IPv4 Settings: Address: 10.21.6.13 Prefix: 24 (255.255.255.0) Gateway: 10.21.6.1 DNS: 10.22.5.133 DNS: 10.22.5.3 

Or to see just the DNS do

yeah this doesn’t work anymore. no nm-tool in 16.x either. nmcli (in Marty Fried’s answer) is the way to go

The two top-scoring answers, nmcli dev list iface | grep IP4 and nm-tool both assume that network-manager is in control. Which it is — on desktop machines most of the time at least. But the fuller answer is that sometimes network-manager is not in control. E.g. vpnc messes with /etc/resolv.conf directly.

So: First check if 127.0.0.1/localhost is used. This could be done with dig :

> dig something.unknown | grep SERVER: ;; SERVER: 127.0.0.1#53(127.0.0.1) 

Now you know that we are using localhost. Go ahead with one of the popular answers. I like:

> nm-tool | grep DNS: DNS: 8.8.8.8 

But if 127.0.0.1/localhost is not used, then nm-tool ‘s and nmcli ‘s output will be misleading:

> dig something.unknown | grep SERVER: ;; SERVER: 172.22.216.251#53(172.22.216.251) > nm-tool | grep DNS: DNS: 8.8.8.8 

Here, dig is correct and nm-tool ‘s information is misleading. In reality addresses local to the environment I’ve VPN-ed into are resolved correctly. All of which Google’s DNS 8.8.8.8 doesn’t know about.

This is because after connecting to a VPN with vpnc , it puts a line in /etc/resolv.conf so it looks like:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 1.2.3.4 nameserver 127.0.0.1 search MyDomain 

Источник

how to list all server services running on my Linux computer

How can I find out the list of all services running on my computer that might give access to hackers to log in to my computer? One day I looked at my /var/log/auth.log from my computer and I discovered there had been several ssh login attempts and that ssh server was installed in my computer. But I couldn’t remember me installing ssh server on this computer. I must have installed some package that depends on ssh package. Made me wonder what other services is running in this computer that I don’t know of.

5 Answers 5

The services need not be running at the time you do your check in order to present a security risk. I’d recommend using a port scanning tool like Nessus or nmap (from an outside machine) to see what ports are open. Then you can look in /etc/services and /etc/xinetd.d to figure out which services are associated with the open ports, and decide whether they can be turned off or blocked.

Читайте также:  Check file version in linux

netstat -lp will give you a list of running servers, along with their pid.

Note that you may want to run that with sudo netstat -lp or as root. Otherwise the process ID info may not be there.

socklist (if installed) — or a portscan from outside (with nmap)

netstat -lp is best way get info who got login to ur server or systemlink text

same good way to block all.

What distro?
You may be able to use a distro specific built in command to determine a bit more.

Exapmle on CentOS / Redhat: chkconfig —list | grep «:on»

will provide you with a listing of services that are up and running and their respective run level.

You could also nmap yourself to see what is listening, in addition to all the excellent netstat suggestions above.

Источник

How to List Services in Ubuntu Server / Desktop

In this tutorial we are going to learn how to list services in Ubuntu using the command line interface. We will see how we can list running services and services that are not running.

List Ubuntu Services with Service command

The service —status-all command will list all services on your Ubuntu Server (Both running services and Not running Services).

This will show all available services on your Ubuntu System. The status is [ + ] for running services, [ — ] for stopped services.

List Ubuntu Services with Service command

Using the grep command, we can filter the output to show only the running services.

To list ubuntu services that are not running, Type,

The service command can be used to list services in all Ubuntu releases, including (Ubuntu 17, 16.04, and 14.04).

List Services with systemctl command

Since Ubuntu 15, the services are managed by the systemd. With systemd we can use systemctl command to get information about running services in our Ubuntu system.

To list all running services on Ubuntu, Type:

The output of the command will look something like this:

UNIT LOAD ACTIVE SUB DESCRIPTION apache2.service loaded active running LSB: Apache2 web server apparmor.service loaded active exited LSB: AppArmor initialization cron.service loaded active running Regular networking.service loaded active exited Raise network interfaces nmbd.service loaded active running LSB: start Samba NetBIOS nameserver (nmbd) smbd.service loaded active running LSB: start Samba SMB/CIFS daemon (smbd) ssh.service loaded active running OpenBSD LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 

To list all services, including inactive units, Type:

To List inactive unit, Type:

systemctl list-units -a --state=inactive

The systemctl command does not work for Ubuntu 14.04 and earlier releases, instead use the service —status-all command mentioned above.

Источник

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