Questo contenuto non è disponibile nella lingua selezionata.

4.4. Configuring Static Routes with ip commands


As a system administrator, you can configure static routes using the ip route command.
To display the IP routing table, use the ip route command. For example: Copy to Clipboard Toggle word wrap
~]$ ip route
default via 192.168.122.1 dev ens9  proto static  metric 1024
192.168.122.0/24 dev ens9  proto kernel  scope link  src 192.168.122.107
192.168.122.0/24 dev enp1s0  proto kernel  scope link  src 192.168.122.126
The ip route commands take the following form: Copy to Clipboard Toggle word wrap
ip route [ add | del | change | append | replace ] destination-address
See the ip-route(8) man page for more details on the options and formats.
To add a static route to a host address, in other words to a single IP address: Copy to Clipboard Toggle word wrap
~]# ip route add 192.0.2.1 via 10.0.0.1 [dev interface]
where 192.0.2.1 is the IP address of the host in dotted decimal notation, 10.0.0.1 is the next hop address and interface is the exit interface leading to the next hop.
To add a static route to a network, in other words to an IP address representing a range of IP addresses: Copy to Clipboard Toggle word wrap
~]# ip route add 192.0.2.0/24 via 10.0.0.1 [dev interface]
where 192.0.2.0 is the IP address of the destination network in dotted decimal notation and /24 is the network prefix. The network prefix is the number of enabled bits in the subnet mask. This format of network address slash network prefix length is sometimes referred to as classless inter-domain routing (CIDR) notation.
To remove the assigned static route: Copy to Clipboard Toggle word wrap
~]# ip route del 192.0.2.1
Any changes that you make to the routing table using ip route do not persist across system reboots. To permanently configure static routes, you can configure them by creating a route-interface file in the /etc/sysconfig/network-scripts/ directory for the interface. For example, static routes for the enp1s0 interface would be stored in the /etc/sysconfig/network-scripts/route-enp1s0 file. Any changes that you make to a route-interface file do not take effect until you restart either the network service or the interface. The route-interface file has two formats:
See the ip-route(8) man page for more information on the ip route command.
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat, Inc.