Walt Mankowski via plug on 27 Dec 2023 11:52:25 -0800 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Configuration of manual IP with commands without ifconfig |
Thank you so much for your help. I had a special need for this Linux box to be extra secure, I removed the network manager and wanted to configure the network manually but I ultimately decided to replace it with OpenBSD which was surprisingly secure on a fresh install and it suited my needs. I hope this is not sacrilege to mention choosing OpenBSD over Linux to meet my very unusual needs.Thank you,Michael Lazin.. τὸ γὰρ αὐτὸ νοεῖν ἐστίν τε καὶ εἶναι.On Tue, Dec 26, 2023 at 10:18 PM Steve Litt via plug <plug@lists.phillylinux.org> wrote:Michael Lazin via plug said on Tue, 26 Dec 2023 13:59:56 -0500>I am hoping someone can give me hints on configuration of a manual IP>using the "ip" command instead of ifconfig. I don't want to make a>confrontation file just configure it manually like I used to with the>ifconfig command. Is this possible? Thanks for your help.>>Michael LazinHi Michael,I can give you simple confrontrations and complex confrontrations. :-)The following is a simple configuration to simply install a static IPaddress:====================================================#!/bin/shhostname=`grep -v "^\s*#" /etc/hostname | head -n1`ip link set dev lo upip link set dev enp6s1 downip addr add 192.168.100.188/24 dev enp6s1ip link set dev enp6s1 upip route add default via 192.168.100.96====================================================Please understand the preceding is so simple that it can error out ifrerun: It's meant to be run once at boot time. This being said, I'veusually been able to get networking running again by simply running itagain and ignoring the error messages.The following is a complex ip command based configuration shellscript,with provisions to completely erase the old network config beforeresetting the network, suitable for a qemu LAN-Peer:===========================================#!/bin/shuse_bridge=1use_tap=0dev="enp40s0"ipaddr_major="192.168.0.2"ipaddr_minor="192.168.0.102"gateway="192.168.0.1"error_tap_without_bridge(){echo -n "ERROR: Can\'t set TAP without "echo -n "BRIDGE! "echo Aborting...exit 1}enable_ip_forwarding(){echo 1 > /proc/sys/net/ipv4/ip_forward}unset_everything(){dev=$1ip_maj=$2ip_min=$3gateway=$4ip link set dev lo downecho "Unsetting everything for $dev, $ip_maj and $ip_min"ip link set dev tap0 downbrctl delif br0 tap0ip link del tap0ip link set dev br0 downip addr del $ip_min/24 dev br0ip addr del $ip_maj/24 dev br0brctl delbr br0ip link set dev $dev downip addr del $ip_min/24 dev $devip addr del $ip_maj/24 dev $devecho ""}set_hostname_and_localhost(){echo "Setting hostname and localhost"hostname=`grep -v "^\s*#" /etc/hostname | head -n1`ip link set dev lo upecho ""}create_phys_device_link(){dev=$1echo Creating device link for $devip link set dev $dev upecho ""}set_phys_device_addr(){dev=$1ip_maj=$2ip_min=$3gateway=$4echo -n "Setting physical device addresses "echo -n "$ip_maj "echo -n "and $ip_min "echo -n "for $physdev "echo "with gateway $gateway"ip link set dev $dev downip addr add $ip_maj/24 dev $devip addr add $ip_min/24 dev $devip link set dev $dev upip route add default via $gatewayecho ""}set_bridge(){dev=$1ip_maj=$2ip_min=$3gateway=$4echo Setting bridge for $devecho -n "Creating and setting bridge addresses "echo -n "$ip_maj "echo -n "and $ip_min "echo -n "for $physdev "echo "with gateway $gateway"ip link add name br0 type bridgeip link set dev $dev master br0ip addr add $ip_maj/24 dev br0ip addr add $ip_min/24 dev br0ip link set dev br0 upip route add default via $gatewayecho ""}set_tap(){echo Setting tapip tuntap add tap0 mode tapbrctl addif br0 tap0ip link set dev tap0 upecho ""}show_networking(){echo -n "Networking follows in 3 seconds..."sleep 3echo "\n"echo "========================================"echo "========================================"ip -4 linkecho "......................"ip -4 addrecho "......................"ip -4 routeecho "========================================"echo "========================================"}echo "\nBegin upnet.sh"[ "$use_tap" = "1" ] && [ "$use_bridge" != "1" ] && \error_tap_without_bridgeunset_everything $dev $ipaddr_major $ipaddr_minor $gatewayenable_ip_forwardingset_hostname_and_localhostcreate_phys_device_link $dev $ipaddr_major $ipaddr_minor $gateway[ "$use_bridge" = "1" ] || \set_phys_device_addr $dev $ipaddr_major $ipaddr_minor $gateway[ "$use_bridge" = "1" ] && set_bridge $dev \$ipaddr_major $ipaddr_minor $gateway[ "$use_tap" = "1" ] && \set_tap $dev $ipaddr_major $ipaddr_minor $gatewayshow_networking===========================================SteveTSteve LittAutumn 2023 featured book: Rapid Learning for the 21st Century___________________________________________________________________________Philadelphia Linux Users Group -- http://www.phillylinux.orgAnnouncements - http://lists.phillylinux.org/mailman/listinfo/plug-announceGeneral Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug___________________________________________________________________________Philadelphia Linux Users Group -- http://www.phillylinux.orgAnnouncements - http://lists.phillylinux.org/mailman/listinfo/plug-announceGeneral Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug