Skip to content

Instantly share code, notes, and snippets.

@awsvpc
Forked from goffinet/net.sh
Created May 3, 2025 04:17
Show Gist options
  • Save awsvpc/c711b99d7ed97730f49cd4cdb871e75a to your computer and use it in GitHub Desktop.
Save awsvpc/c711b99d7ed97730f49cd4cdb871e75a to your computer and use it in GitHub Desktop.

Revisions

  1. @goffinet goffinet revised this gist Mar 12, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions net.sh
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,8 @@ nmcli c up "$connection"
    sysctl -w net.ipv4.ip_forward=1
    sysctl -w net.ipv6.conf.all.forwarding=1
    sysctl -p
    echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf
    echo "net.ipv6.conf.all.forwarding=1" > /etc/sysctl.conf
    echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
    echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
    }
    3_firewall () {
    systemctl enable firewalld
  2. @goffinet goffinet revised this gist Mar 12, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions net.sh
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,8 @@ nmcli c up "$connection"
    sysctl -w net.ipv4.ip_forward=1
    sysctl -w net.ipv6.conf.all.forwarding=1
    sysctl -p
    echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf
    echo "net.ipv6.conf.all.forwarding=1" > /etc/sysctl.conf
    }
    3_firewall () {
    systemctl enable firewalld
  3. @goffinet goffinet revised this gist Mar 11, 2017. No changes.
  4. @goffinet goffinet revised this gist Mar 11, 2017. 1 changed file with 19 additions and 10 deletions.
    29 changes: 19 additions & 10 deletions net.sh
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,42 @@
    #!/bin/bash
    1_interfaces-ipv4 () {
    connection="System eth0"
    ip4="192.168.168"
    ip6="fd00:168:168"
    1_interfaces () {
    hostnamectl set-hostname router
    nmcli c mod eth0 ipv4.addresses 192.168.168.1/24
    nmcli c mod eth0 ipv4.method manual
    nmcli c mod eth0 connection.zone internal
    nmcli c up eth0
    nmcli c mod "$connection" ipv4.addresses $ip4.1/24
    nmcli c mod "$connection" ipv4.method manual
    nmcli c mod "$connection" ipv6.addresses $ip6::1/64
    nmcli c mod "$connection" ipv6.method manual
    nmcli c mod "$connection" connection.zone internal
    nmcli c up "$connection"
    }
    2_routing () {
    sysctl -w net.ipv4.ip_forward=1
    sysctl -w net.ipv6.conf.all.forwarding=1
    sysctl -p
    }
    3_firewall () {
    systemctl enable firewalld
    systemctl start firewalld
    firewall-cmd --zone=internal --add-service=dns --permanent
    firewall-cmd --zone=internal --add-service=dhcp --permanent
    firewall-cmd --zone=internal --add-source=192.168.168.0/24 --permanent
    firewall-cmd --zone=internal --add-service=dhcpv6 --permanent
    firewall-cmd --zone=internal --add-source=${ip4}.0/24 --permanent
    firewall-cmd --zone=internal --add-source=${ip6}::/64 --permanent
    firewall-cmd --zone=public --add-masquerade --permanent
    firewall-cmd --reload
    }
    4_dhcp-dns () {
    yum -y install dnsmasq*
    echo "dhcp-range=192.168.168.50,192.168.168.150,255.255.255.0,12h" > /etc/dnsmasq.d/eth0.conf
    echo "dhcp-option=3,192.168.168.1" >> /etc/dnsmasq.d/eth0.conf
    echo "dhcp-range=$ip4.50,$ip4.150,255.255.255.0,12h" > /etc/dnsmasq.d/eth0.conf
    echo "dhcp-option=3,$ip4.1" >> /etc/dnsmasq.d/eth0.conf
    echo "dhcp-range=$ip6::2,$ip6::500,slaac" >> /etc/dnsmasq.d/eth0.conf
    systemctl enable dnsmasq
    systemctl start dnsmasq
    }

    1_interfaces-ipv4
    1_interfaces
    2_routing
    3_firewall
    4_dhcp-dns
    4_dhcp-dns
  5. @goffinet goffinet revised this gist Dec 22, 2016. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions net.sh
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,33 @@
    #!/bin/bash
    main () {
    1_interfaces-ipv4 () {
    hostnamectl set-hostname router
    nmcli c mod eth0 ipv4.addresses 192.168.168.1/24
    nmcli c mod eth0 ipv4.method manual
    nmcli c mod eth0 connection.zone internal
    nmcli c up eth0
    }
    2_routing () {
    sysctl -w net.ipv4.ip_forward=1
    sysctl -p
    }
    3_firewall () {
    systemctl enable firewalld
    systemctl start firewalld
    firewall-cmd --zone=internal --add-service=dns --permanent
    firewall-cmd --zone=internal --add-service=dhcp --permanent
    firewall-cmd --zone=internal --add-source=192.168.168.0/24 --permanent
    firewall-cmd --zone=public --add-masquerade --permanent
    firewall-cmd --reload
    }
    4_dhcp-dns () {
    yum -y install dnsmasq*
    echo "dhcp-range=192.168.168.50,192.168.168.150,255.255.255.0,12h" > /etc/dnsmasq.d/eth0.conf
    echo "dhcp-option=3,192.168.168.1" >> /etc/dnsmasq.d/eth0.conf
    systemctl enable dnsmasq
    systemctl start dnsmasq
    }

    main
    1_interfaces-ipv4
    2_routing
    3_firewall
    4_dhcp-dns
  6. @goffinet goffinet created this gist Dec 18, 2016.
    24 changes: 24 additions & 0 deletions net.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash
    main () {
    hostnamectl set-hostname router
    nmcli c mod eth0 ipv4.addresses 192.168.168.1/24
    nmcli c mod eth0 ipv4.method manual
    nmcli c mod eth0 connection.zone internal
    nmcli c up eth0
    sysctl -w net.ipv4.ip_forward=1
    sysctl -p
    systemctl enable firewalld
    systemctl start firewalld
    firewall-cmd --zone=internal --add-service=dns --permanent
    firewall-cmd --zone=internal --add-service=dhcp --permanent
    firewall-cmd --zone=internal --add-source=192.168.168.0/24 --permanent
    firewall-cmd --zone=public --add-masquerade --permanent
    firewall-cmd --reload
    yum -y install dnsmasq*
    echo "dhcp-range=192.168.168.50,192.168.168.150,255.255.255.0,12h" > /etc/dnsmasq.d/eth0.conf
    echo "dhcp-option=3,192.168.168.1" >> /etc/dnsmasq.d/eth0.conf
    systemctl enable dnsmasq
    systemctl start dnsmasq
    }

    main