How to add multiple interfaces to trusted zone using firewalld command?

5,812

This will get all the device names and then proceed to run the command for every interface.

for i in $( ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d' ); do
    firewall-cmd --zone=trusted --change-interface=$i
    echo "Added $i to trusted\n"
done
Share:
5,812

Related videos on Youtube

Neeraj
Author by

Neeraj

Updated on September 18, 2022

Comments

  • Neeraj
    Neeraj over 1 year

    I am adding a particular interface as an trusted zone using below command

    firewall-cmd --zone=trusted --change-interface=eth0
    

    Now suppose I have multiple interfaces(like eth0, eth1, bond0, bond1) and I want to add all of them once, by executing the above command written in a bash script.

    What will be the syntax and command for adding all the interfaces by executing above command once?

  • Neeraj
    Neeraj over 6 years
    It would be really great if you can explain the working of this 's/[ \t].*//;/^(lo\|)$/d' syntax. Thanks
  • Hunter.S.Thompson
    Hunter.S.Thompson over 6 years
    Lot to explain.. Look at this grymoire.com/Unix/SedChart.pdf . It will explain well what the syntax means.