+
+
+
+
+
โˆ‰
esbuild
ios
+
+
aurelia
!==
+
+
โ‰ˆ
node
+
https
eclipse
+
+
elementary
gcp
...
||
mysql
+
+
โˆฉ
+
weaviate
delphi
gh
+
redhat
c
+
dart
c++
bsd
+
~
+
+
+
delphi
+
+
alpine
+
qdrant
+
=>
elementary
+
+
htmx
+
+
composer
+
+
css
+
&&
+
+
neo4j
+
erlang
+
โˆ‘
htmx
marko
r
clj
+
rollup
saml
numpy
+
+
โ‰ˆ
+
actix
pandas
<-
+
+
+
Back to Blog
๐ŸŒ Configuring Network Routing: Simple Guide
Alpine Linux Network Routing Networking

๐ŸŒ Configuring Network Routing: Simple Guide

Published Jun 3, 2025

Easy tutorial for setting up network routing on Alpine Linux. Perfect for beginners with step-by-step instructions and clear examples.

11 min read
0 views
Table of Contents

๐ŸŒ Configuring Network Routing: Simple Guide

Ready to set up network routing on Alpine Linux? This is exciting! ๐ŸŽ‰ Weโ€™ll learn how to direct network traffic. Your computer will know where to send data! ๐Ÿ˜Š

๐Ÿค” What is Network Routing?

Network routing tells your computer how to send data to other computers. Think of it like GPS for internet traffic!

Routing helps with:

  • ๐Ÿšฆ Directing traffic to the right place
  • ๐Ÿ”€ Choosing the best path for data
  • ๐ŸŒ Connecting different networks together

๐ŸŽฏ What You Need

Before we start, you need:

  • โœ… Alpine Linux system with network access
  • โœ… Root access for network configuration
  • โœ… Basic understanding of IP addresses
  • โœ… Knowledge of your network setup

๐Ÿ“‹ Step 1: Understanding Current Routes

Viewing the Routing Table

Letโ€™s see what routes your system already knows! This is the foundation! ๐Ÿ˜Š

What weโ€™re doing: Checking the current routing configuration.

# Show current routing table
route -n

# Alternative: using ip command
ip route show

# Show detailed route information
ip route show table all

# Check default gateway
ip route | grep default

What this does: ๐Ÿ“– Shows all the paths your computer knows for sending data.

Example output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

What this means: Your computer knows how to reach the internet through 192.168.1.1! โœ…

๐Ÿ’ก Important Tips

Tip: Always backup your current routes before making changes! ๐Ÿ’ก

Warning: Wrong routes can break internet connectivity! โš ๏ธ

๐Ÿ› ๏ธ Step 2: Basic Route Configuration

Adding Static Routes

Now letโ€™s add new routes! This directs traffic to specific destinations! ๐ŸŽฏ

What weโ€™re doing: Creating custom routes for specific networks.

# Add route to specific network
ip route add 10.0.0.0/24 via 192.168.1.10

# Add route through specific interface
ip route add 172.16.0.0/16 dev eth1

# Add default route
ip route add default via 192.168.1.1

# Add route with metric (priority)
ip route add 10.1.0.0/24 via 192.168.1.20 metric 100

Code explanation:

  • 10.0.0.0/24: Network destination (IP range)
  • via 192.168.1.10: Gateway to use for this route
  • dev eth1: Interface to use directly
  • metric 100: Route priority (lower numbers = higher priority)

Expected Output:

โœ… Route to 10.0.0.0/24 added successfully
โœ… Route via eth1 configured

What this means: Your computer now knows new paths to send data! ๐ŸŒŸ

Deleting Routes

What weโ€™re doing: Removing routes we donโ€™t need anymore.

# Remove specific route
ip route del 10.0.0.0/24 via 192.168.1.10

# Remove route by destination only
ip route del 172.16.0.0/16

# Remove default route
ip route del default via 192.168.1.1

# Check routes after deletion
ip route show

What this does: Cleans up routing table by removing unused paths! ๐Ÿ“š

๐Ÿ“Š Quick Summary Table

CommandPurposeResult
๐ŸŒ ip route showView routesโœ… Shows routing table
โž• ip route addAdd new routeโœ… Creates path
โž– ip route delRemove routeโœ… Deletes path
๐Ÿ”ง route -nShow numeric routesโœ… Displays all routes

๐ŸŽฎ Step 3: Advanced Routing Configuration

Setting Up Multiple Gateways

Letโ€™s configure multiple internet connections! This is powerful! ๐ŸŒŸ

What weโ€™re doing: Setting up load balancing and failover between gateways.

# Install routing utilities
apk add iproute2 iptables

# Create routing tables
echo "200 wan1" >> /etc/iproute2/rt_tables
echo "201 wan2" >> /etc/iproute2/rt_tables

# Configure first gateway
ip route add default via 192.168.1.1 dev eth0 table wan1
ip rule add from 192.168.1.0/24 table wan1

# Configure second gateway
ip route add default via 192.168.2.1 dev eth1 table wan2
ip rule add from 192.168.2.0/24 table wan2

# Set up load balancing
ip route add default scope global \
    nexthop via 192.168.1.1 dev eth0 weight 1 \
    nexthop via 192.168.2.1 dev eth1 weight 1

What this does: Creates smart routing with multiple internet connections! ๐Ÿš€

Policy-Based Routing

What weโ€™re doing: Creating rules that route traffic based on specific criteria.

# Route traffic from specific source
ip rule add from 10.0.1.0/24 table wan1 priority 100

# Route traffic to specific destination
ip rule add to 8.8.8.8 table wan2 priority 200

# Route traffic based on port
iptables -t mangle -A OUTPUT -p tcp --dport 80 -j MARK --set-mark 1
ip rule add fwmark 1 table wan1 priority 300

# Create rules for different services
ip rule add from 192.168.1.100 table wan2 priority 150
ip rule add to 192.168.10.0/24 table wan1 priority 250

# Show all rules
ip rule show

Expected Output:

0:      from all lookup local
100:    from 10.0.1.0/24 lookup wan1
150:    from 192.168.1.100 lookup wan2
200:    to 8.8.8.8 lookup wan2
250:    to 192.168.10.0/24 lookup wan1
300:    from all fwmark 0x1 lookup wan1
32766:  from all lookup main
32767:  from all lookup default

What this means: Traffic follows smart rules based on source and destination! ๐ŸŽ‰

๐ŸŽฎ Practice Time!

Letโ€™s practice what you learned! Try these simple examples:

Example 1: Create Network Segments ๐ŸŸข

What weโ€™re doing: Setting up routing between different network segments.

# Create virtual interfaces for testing
ip link add veth0 type veth peer name veth1
ip link set veth0 up
ip link set veth1 up

# Assign IP addresses
ip addr add 10.1.1.1/24 dev veth0
ip addr add 10.2.2.1/24 dev veth1

# Create routes between segments
ip route add 10.1.1.0/24 dev veth0
ip route add 10.2.2.0/24 dev veth1

# Test connectivity
ping -c 3 10.1.1.1
ping -c 3 10.2.2.1

# Show routing table
ip route show | grep "10\."

echo "Network segments configured! โœ…"

What this does: Creates separate network segments with proper routing! ๐ŸŒŸ

Example 2: Configure Route Persistence ๐ŸŸก

What weโ€™re doing: Making routes survive system reboots.

# Create network configuration file
cat > /etc/network/interfaces << 'EOF'
# Alpine Linux network configuration
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    up ip route add 10.0.0.0/8 via 192.168.1.10
    up ip route add 172.16.0.0/12 via 192.168.1.20
    down ip route del 10.0.0.0/8 via 192.168.1.10
    down ip route del 172.16.0.0/12 via 192.168.1.20
EOF

# Create custom routing script
cat > /etc/local.d/custom-routes.start << 'EOF'
#!/bin/sh
# Custom routing configuration

# Add static routes
ip route add 192.168.100.0/24 via 192.168.1.50
ip route add 192.168.200.0/24 via 192.168.1.60

# Configure policy routing
ip rule add from 192.168.1.0/24 table main priority 100
EOF

chmod +x /etc/local.d/custom-routes.start

# Enable local.d service
rc-update add local default

# Test configuration
/etc/local.d/custom-routes.start

echo "Persistent routing configured! ๐Ÿ“š"

What this does: Ensures your routing configuration survives reboots! ๐Ÿ“š

๐Ÿšจ Fix Common Problems

Problem 1: Route not working โŒ

What happened: Added route but traffic doesnโ€™t flow. How to fix it: Check route details and connectivity!

# Verify route was added
ip route show | grep "your-destination"

# Test gateway connectivity
ping -c 3 192.168.1.1

# Check interface status
ip link show

# Verify IP forwarding is enabled
sysctl net.ipv4.ip_forward

# Enable IP forwarding if needed
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

Problem 2: Multiple routes conflict โŒ

What happened: Different routes pointing to same destination. How to fix it: Check route priorities and remove conflicts!

# Show routes with metrics
ip route show | grep "your-destination"

# Remove conflicting route
ip route del conflicting-route

# Add route with specific metric
ip route add 10.0.0.0/24 via 192.168.1.10 metric 100

# Verify only one route exists
ip route show | grep "10.0.0.0/24"

Problem 3: Routes disappear after reboot โŒ

What happened: Routes donโ€™t persist after restart. How to fix it: Make configuration permanent!

# Check if networking service is enabled
rc-status | grep networking

# Create persistent route file
echo "ip route add 10.0.0.0/24 via 192.168.1.10" > /etc/conf.d/net.eth0

# Or add to interfaces file
echo "    up ip route add 10.0.0.0/24 via 192.168.1.10" >> /etc/network/interfaces

# Restart networking
rc-service networking restart

Donโ€™t worry! Network routing takes practice. Youโ€™re doing great! ๐Ÿ’ช

๐Ÿ’ก Simple Tips

  1. Test carefully ๐Ÿ“… - Small changes first
  2. Document routes ๐ŸŒฑ - Keep notes of what you add
  3. Use metrics ๐Ÿค - Set priorities properly
  4. Monitor traffic ๐Ÿ’ช - Watch what happens

โœ… Check Everything Works

Letโ€™s verify routing is working correctly:

# Check routing table
ip route show

# Test default gateway
ping -c 3 $(ip route | grep default | awk '{print $3}')

# Test internet connectivity
ping -c 3 8.8.8.8

# Check route to specific destination
traceroute 8.8.8.8

# Verify policy rules
ip rule show

# Test custom routes if configured
ping -c 3 10.0.0.1

echo "Network routing verification completed! โœ…"

Good output:

default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 scope link
PING 192.168.1.1: 3 packets transmitted, 3 received
PING 8.8.8.8: 3 packets transmitted, 3 received
โœ… Traceroute shows proper path
Network routing verification completed! โœ…

๐Ÿ”ง Advanced Routing Features

Dynamic Routing with BIRD

Letโ€™s set up dynamic routing for complex networks! This is professional! ๐ŸŽฏ

What weโ€™re doing: Installing and configuring BIRD routing daemon.

# Install BIRD routing daemon
apk add bird

# Create BIRD configuration
cat > /etc/bird.conf << 'EOF'
# BIRD Routing Daemon Configuration

# Router ID (use your main IP)
router id 192.168.1.100;

# Enable debugging
debug protocols all;

# Device protocol for interface discovery
protocol device {
    scan time 10;
}

# Direct protocol for directly connected networks
protocol direct {
    interface "*";
}

# Kernel protocol to sync with system routing table
protocol kernel {
    export all;
    scan time 20;
}

# Static routes
protocol static {
    route 10.0.0.0/8 via 192.168.1.10;
    route 172.16.0.0/12 via 192.168.1.20;
}

# OSPF protocol for dynamic routing
protocol ospf {
    area 0.0.0.0 {
        interface "eth0" {
            hello 10;
            dead count 5;
        };
    };
}
EOF

# Start BIRD daemon
rc-service bird start
rc-update add bird default

# Check BIRD status
birdc show protocols
birdc show route

What this does: Creates professional dynamic routing capabilities! ๐ŸŒŸ

Network Monitoring and Troubleshooting

What weโ€™re doing: Setting up tools to monitor and debug routing.

# Install network monitoring tools
apk add tcpdump wireshark-common mtr

# Create network monitoring script
cat > /usr/local/bin/network-monitor.sh << 'EOF'
#!/bin/sh
# Network Routing Monitor

LOG_FILE="/var/log/network-monitor.log"

log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S'): $1" | tee -a "$LOG_FILE"
}

# Check routing table changes
check_routes() {
    local current_routes=$(ip route show | md5sum)
    local stored_routes="/tmp/last_routes.md5"
    
    if [ -f "$stored_routes" ]; then
        if [ "$current_routes" != "$(cat $stored_routes)" ]; then
            log_message "Routing table changed!"
            ip route show | tee -a "$LOG_FILE"
        fi
    fi
    
    echo "$current_routes" > "$stored_routes"
}

# Test gateway connectivity
test_gateways() {
    ip route | grep "^default" | while read route; do
        gateway=$(echo $route | awk '{print $3}')
        if ping -c 1 -W 2 "$gateway" >/dev/null 2>&1; then
            log_message "Gateway $gateway: OK"
        else
            log_message "Gateway $gateway: FAILED"
        fi
    done
}

# Monitor network interfaces
check_interfaces() {
    ip link show | grep "state DOWN" | while read line; do
        interface=$(echo $line | awk '{print $2}' | sed 's/:$//')
        log_message "Interface $interface is DOWN"
    done
}

# Run checks
log_message "=== Network monitoring started ==="
check_routes
test_gateways
check_interfaces
log_message "=== Network monitoring completed ==="
EOF

chmod +x /usr/local/bin/network-monitor.sh

# Set up monitoring cron job
echo "*/5 * * * * /usr/local/bin/network-monitor.sh" | crontab -

# Test monitoring
/usr/local/bin/network-monitor.sh

echo "Network monitoring configured! ๐Ÿ“Š"

Expected Output:

2025-06-03 18:45:01: === Network monitoring started ===
2025-06-03 18:45:01: Gateway 192.168.1.1: OK
2025-06-03 18:45:01: === Network monitoring completed ===
Network monitoring configured! ๐Ÿ“Š

What this means: You have professional network monitoring! ๐ŸŽ‰

๐Ÿ† What You Learned

Great job! Now you can:

  • โœ… View and understand routing tables
  • โœ… Add and remove static routes
  • โœ… Configure advanced routing with multiple gateways
  • โœ… Set up persistent routing and monitoring!

๐ŸŽฏ Whatโ€™s Next?

Now you can try:

  • ๐Ÿ“š Learning about BGP routing for large networks
  • ๐Ÿ› ๏ธ Setting up VPN routing and tunnels
  • ๐Ÿค Implementing quality of service (QoS) routing
  • ๐ŸŒŸ Building complex multi-homed network setups!

Remember: Every network engineer was once a beginner. Youโ€™re doing amazing! ๐ŸŽ‰

Keep practicing and youโ€™ll become an expert too! ๐Ÿ’ซ