What I like to know is if network programs still use this file?

I can comment out http port 80 without any effects on firefox:

># http 80/tcp
># http 80/udp

Then I can delete out /etc/services without no serious effects on the system:

>sudo rm -v /etc/services

The best of what I know is to manually enable/disable network services with systemd:

>sudo systemctl enable NAME
>sudo systemctl disable NAME

The next question is how would I get the list of network services to enable/disable all in
one config/script file on linux mint?

Dani AI

Generated

Short answer: /etc/services is still used — but only as a name ↔ port mapping, not as a service controller. It is consulted by programs that call the libc service lookup APIs (getservbyname/getservbyport) via the NSS “services” database, so some scripts/tools expect it. Many modern apps (browsers, daemons started with explicit numeric ports, services that bundle their own mappings) will keep working if entries are removed, which explains ’s Firefox observation.

Quick checks to see whether name-to-port resolution still works:

getent services http
python3 - <<'PY'
import socket
try:
    print(socket.getservbyname("http","tcp"))
except Exception as e:
    print("lookup failed:", e)
PY

If those return nothing or an error, programs that call the service lookup API will be affected.

Clarification about systemd vs /etc/services: systemd unit files control daemon lifecycle at boot and runtime; they do not read /etc/services. is correct to point to systemd for enable/disable/management of daemons. A compact workflow to build a single config of units and apply an action (start/stop/enable/disable/mask/etc.):

#!/bin/sh
action="$1"    # start|stop|mask|unmask|enable|disable
list="$2"      # newline-separated unit names, e.g. ssh.service
while IFS= read -r u; do
  [ -z "$u" ] && continue
  sudo systemctl "$action" "$u" || printf 'failed: %s\n' "$u"
done <"$list"

Populate that unit list by inspecting listening sockets (ss -ltnp / ss -lunp) and mapping PIDs to binaries with ps -p <pid> -o comm,args, then matching those binaries to unit files under /lib/systemd/system or /etc/systemd/system.

Practical advice: do not blindly delete /etc/services — back it up first. For disabling network access prefer firewall rules or masking systemd units. Experimentation that involves removing system files is safest in a container or VM.

Recommended Answers

All 2 Replies

List of enabled/disabled srvices ~$ systemctl list-unit-files
Script for enable:

#!/bin/bash

for i in $*
do
    sudo systemctl enable $i
done

Call above script with passing multiple arguments or call below script with hardcoded services

#!/bin/bash

for i in eg_service_1 eg_service_2 eg_service_3
do
    sudo systemctl enable $i
done

Command enable/disable managed auto start of service on PC switch on or restart but for start/stop service must be used start/stop/restart command or you can check status using command status e.g.

systemctl status apache2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.