티스토리 뷰
참조 : https://www.cyberciti.biz/tips/configuring-static-routes-in-debian-or-red-hat-linux-systems.html
Configure Static Routes In Debian or Red Hat Enterprise Linux
Static routes improve the overall performance of your network (especially bandwidth saving). They are also useful in stub networks (i.e. there is only one link to the network). For example, each LAN (located at different offices) is connected to HQ IDC (Internet data center) using single T1/LL/Wan links.
For example under Red Hat/Fedora Linux you can add a static route for eth0 network interface by editing /etc/sysconfig/network-scripts/route-eth0 file. Under Debian Linux add static route by editing /etc/network/interface file.
Display Current Routing Table Using ip command
By using the ip command, you can set up and view static route. For example, to display the current routing table you can type the command:
# ip route show
Sample output:
192.168.2.0/24 dev eth1 proto kernel scope link src 192.168.2.1
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.2
default via 192.168.1.254 dev eth0
You can add static route using following command:
ip route add {NETWORK} via {IP} dev {DEVICE}
For example network 192.168.55.0/24 available via 192.168.1.254:
# ip route add 192.168.55.0/24 via 192.168.1.254 dev eth1
Alternatively, you can use old good route command too:
# route add -net 192.168.55.0 netmask 255.255.255.0 gw 192.168.1.254 dev eth1
- 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:
Linux Persistence Routes
The drawback of ‘ip’ or ‘route’ command is that when Linux system reboots it will forget static routes. So store them in a configuration file. Static routing describes a system that does not implement adaptive routing. In these systems routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator
Red Hat (RHEL) / CentOS / Fedora Linux Persistence Static Routing
You need to open /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface:
# cat /etc/sysconfig/network-scripts/route-eth0
Sample Output:
GATEWAY0=192.168.1.254
NETMASK0=255.255.255.0
ADDRESS0=192.168.55.0
GATEWAY1=10.164.234.112
NETMASK1= 255.255.255.240
ADDRESS1=10.164.234.132
A note about CentOS 7.x/RHEL 7.x and permanent static route
On a modern version of CentOS 7 or RHEL 7, you need to create a file named /etc/sysconfig/network-scripts/route-eth0 and update as follows:
# vi /etc/sysconfig/network-scripts/route-eth0
Add a permanent static route:
172.16.1.0/24 via 10.10.8.254 dev eth0
Save and close the file. You must restart networking service:
# systemctl restart network
OR
# service restart network
Related: Red Hat Enterprise Linux Static Routing Configuration For v 4.x/5.x/6.x/7.x
How do I define static routing for network 10.0.0.0/8 via 10.9.38.65 router?
Open /etc/sysconfig/network-scripts/route-eth0:
# vi /etc/sysconfig/network-scripts/route-eth0
Append following line:
10.0.0.0/8 via 10.9.38.65
Save and close the file. Restart networking:
# service network restart
Verify new routing table:
# route -n
Debian / Ubuntu Linux Persistence Static Routing
Open configuration file /etc/network/interfaces to configure static routes in Debian or Ubuntu Linux:
# cat /etc/network/interfaces
Sample outputs:
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254
up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
down route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
Debian / Ubuntu Linux static routing for two interfaces:
Here is an updated config file named /etc/network/interfaces:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.9.38.76
netmask 255.255.255.240
network 10.9.38.64
broadcast 10.9.38.79
### static routing for eth0 that connects to the VLAN ###
post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65
pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65
auto eth1
iface eth1 inet static
address 204.186.149.140
netmask 255.255.255.240
network 204.186.149.128
broadcast 204.186.149.143
## default gateway for eth1 and the server ##
gateway 204.186.149.129
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 10.0.80.11 10.0.80.12
dns-search nixcraft.in
Conclusion
Please note that the route command has been deprecated. Please use the ip command or see the following tutorials:
'Study > System' 카테고리의 다른 글
[centos7] python 설치 (0) | 2023.01.26 |
---|---|
Windows 10 cmd 창 안 열릴 때 (0) | 2022.05.27 |
MAN Page - pam_tally2 (0) | 2019.07.19 |
Disable FSCK on Linux (0) | 2018.02.22 |
rpm 패키지 관리 (0) | 2017.09.12 |
- Total
- Today
- Yesterday
- NX ASLR
- tshark
- editcap
- capinfos
- recovery file on linux
- ${1##*.}
- dvwa_bruteforce
- dvwa_command
- megacli
- 리눅스 버전
- tcpdstat
- cisco ssh
- history timestamp
- ssl decrypt
- MySQL csv
- text2pcap
- dvwa
- 윈도우 패스워드 복구
- mergecap
- filesystem check
- docker
- bash parameter
- webhack
- excel_aton
- metasploitable3
- oracle 11gr2
- 도커
- bash modification
- pcapng
- docker_dvwa
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |