mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

  1. #!/bin/bash
  2. echo
  3. echo "# IP-Tables configuration"
  4. while read line; do
  5. [ -z "${line##\**}" ] && table="${line#\*}"
  6. [ -z "${line##-A*}" ] && echo iptables -t $table $line
  7. done < <( iptables-save )
  8. echo
  9. echo "# Link Configuration"
  10. ip link | awk -- '
  11. BEGIN {
  12. f["ARP"] = "on";
  13. f["MULTICAST"] = "on";
  14. f["ALLMULTI"] = "off";
  15. f["PROMISC"] = "off";
  16. f["DYNAMIC"] = "off";
  17. a["00:00:00:00:00:00"] = 1;
  18. a["ff:ff:ff:ff:ff:ff"] = 1;
  19. }
  20. /^[0-9]/ {
  21. if ( command ) print command updown;
  22. interface = $2;
  23. sub(":", "", interface);
  24. command = "ip link set " interface;
  25. updown = " down";
  26. if ( match($3, "[^A-Z]UP[^A-Z]") ) updown = " up";
  27. for ( field in f ) {
  28. val = f[field];
  29. if ( match($3, "[^A-Z]" field "[^A-Z]") ) val = "on";
  30. if ( match($3, "[^A-Z]NO" field "[^A-Z]") ) val = "off";
  31. if ( val != f[field] && val != "auto" ) {
  32. command = command " " tolower(field) " " val;
  33. }
  34. }
  35. if ( $4 == "mtu" ) {
  36. command = command " mtu " $5;
  37. }
  38. }
  39. /^ *link\// {
  40. if ( ! a[$2] ) command = command " address " $2;
  41. if ( ! a[$4] ) command = command " broadcast " $4;
  42. }
  43. END {
  44. if ( command ) print command updown;
  45. }
  46. '
  47. echo
  48. echo "# IPv4 Address Configuration"
  49. ip addr | grep '^ *inet ' | sed 's, *inet,ip addr add,; s,\(.*\) ,\1 dev ,'
  50. echo
  51. echo "# IPv4 Route Configuration"
  52. ip route | grep -v ' scope link ' | sed 's,^,ip route add ,'
  53. echo