- Маршрутизация в Linux
- Материал из Xgu.ru
- Содержание
- [править] Команды
- [править] Использование route
- [править] Использование ip
- [править] Действия с маршрутами
- [править] Equal Cost Multi Path
- [править] IPv6
- [править] Просмотр маршрутов до определенной сети
- [править] Пересылка пакетов между интерфейсами
- [править] Конфигурационные файлы
- [править] Policy routing
- Настройка сетевых маршрутов в Linux (CentOS)
- Просмотр таблицы маршрутизации в Linux
- Как добавить или удалить статический маршрут?
- Изменить маршрут в Linux
- Изменить маршрут по умолчанию
- Linux Set Up Routing with ip Command
- How to view or display Linux routing table
- How to set a route to the locally connected network eth0 on Linux
- Set a default route
- Delete route from table
- How do I verify routing configurations?
- Linux Set Up Routing with ip command and save it to a configuration file
- How to add a static route on Ubuntu or Debian
- ip route show src field
- 2 Answers 2
Маршрутизация в Linux
Материал из Xgu.ru
Linux предоставляет большой набор функций для маршрутизации и инструменты для ее настройки. Ядро 2.6.x поддерживает:
- Простую статическую маршрутизацию.
- Equal Cost Multi Path маршруты (маршруты до одной сети с одинаковым весом, которые выбираются с равной вероятностью).
- Blackhole-маршруты.
- Множественные таблицы маршрутизации.
- Policy Based Routing
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | ip command |
Est. reading time | 10m |
- Show / manipulate routing
- Show / manipulate devices
- Policy routing
- Tunnels
How to view or display Linux routing table
Type the following command:
$ ip route show
OR
$ ip route list
Sample Outputs:
Each entry is nothing but an entry in the routing table (Linux kernel routing table). For example, the following line represents the route for the local network. All network packets to a system in the same network are sent directly through the device ra0:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Our default route is set via ra0 interface i.e. all network packets that cannot be sent according to the previous entries of the routing table are sent through the gateway defined in this entry i.e 192.168.1.1 is our default gateway.
How to set a route to the locally connected network eth0 on Linux
Type the following command to sent all packets to the local network 192.168.1.0 directly through the device eth0:, enter:
# ip route add 192.168.1.0/24 dev eth0
OR route traffic via 192.168.2.254 gateway for 192.168.2.0/24 network:
# ip route add 192.168.2.0/24 via 192.168.2.254 dev eth0
Set a default route
All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway:
# ip route add default via 192.168.1.254
Delete route from table
Type the following command
# ip route delete 192.168.1.0/24 dev eth0
Let us delete default route too:
# ip route add default via 192.168.1.254 dev eth0
Linux add a default route/static route or delete a route using the ip command.
How do I verify routing configurations?
Use the ping command or host command commands to make sure you can reach to your gateway:
ping Your-Gateway-Ip-Here
ping Your-DNS-Server-IP-Here
ping 192.168.1.254
ping www.cyberciti.biz
host www.cyberciti.biz
Linux Set Up Routing with ip command and save it to a configuration file
All routing settings made with the ip tool (or route command) are lost when you reboot Linux server. See our previous article about configuring static routes in a Debian/Ubuntu or CentOS/Red Hat Enteprise Linux systems.
How to add a static route on Ubuntu or Debian
Here is a sample for eth0 displayed using the cat command cat /etc/network/interfaces
Источник
ip route show src field
I read the man page of ip and still do not understand what src is and I could not find much documentation.
Please, if you can explain it thoroughly or point to some link it a good answer.
2 Answers 2
When adding a route to a multihomed host, you might want to have control over the source IP address your host is sending from when starting communications using this route. This is what src is for.
A short example: you have a host with two interfaces and the IP addresses 192.168.1.123/24 and 10.45.22.12/24. You are adding a route to 78.22.45.0/24 via 10.45.22.1 and want to make sure you are not sending to 78.22.45.0/24 using the 192.168.1.123 address (maybe because the network 78.22.45.0/24 has no route back to 192.168.1.0/24 or because you do not want your traffic to take this route for one reason or the other):
Note that the src you are giving would only affect the traffic originating at your very host. If a foreign packet is being routed, it obviously would already have a source IP address so it would be passed on unaltered (unless you are using NAT of course, but this is an entirely different matter). Also, this setting might be overridden by a process specifically choosing to bind to a specific address instead of using the defaults when initiating connections (rather rare).
The src attribute is a hint that is used by the address selection algorithm. It is significant when a host has multiple IP addresses, which is usually, but not always, when it has multiple interfaces. While there are other rules that influence address selection, and a network application can also override the selection algorithm by using system calls like bind() , the src attribute is a way to use a routing-table lookup to answer the question, «If I want to initiate a connection to host X, which of my addresses should I use?»
Here is an example to illustrate the use and effect of the src attribute. To make the point that this is related to addresses and routes, not strictly to interfaces, this example host has only one network interface but two addresses. Furthermore, both addresses are on the same subnet to emphasize the fact that there is no other obvious way to choose which one to use.
This host can communicate with any of the other 252 addresses on this /24 subnet from either address, but by default it will use 10.1.0.16 when initiating a connection with 10.1.0.32 through 10.1.0.63, and use 10.1.0.2 for all the rest.
If the host is responding, rather than initiating, then it will respond from the destination address of the request. For example, if another host at 10.1.0.32 connects to this host at 10.1.0.2, the response will come from 10.1.0.2 even though that doesn’t match the src attribute of the return route.
Источник