Skip to content

digilolnet/go-firewalld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-firewalld

Go report GoDoc License

Go wrapper for firewalld D-Bus interface.

Digilol offers managed hosting and software development

Usage

package main

import (
	"log"

	"github.com/digilolnet/go-firewalld"
)

func main() {
	fw, err := firewalld.NewFirewalldClient()
	if err != nil {
		log.Println(err)
	}

	// Add new chain using permanent direct rule
	if err := fw.DirectAddChainPermanent("ipv4", "filter", "MYCHAIN"); err != nil {
		log.Println(err)
	}

	// Handle packets related to processes with owner UID 1000 at MYCHAIN
	if err := fw.DirectAddRulePermanent("ipv4", "filter", "OUTPUT", 0, "-m owner --uid-owner 1000 -j MYCHAIN"); err != nil {
		log.Println(err)
	}

	if err := fw.DirectAddRulePermanent("ipv4", "filter", "MYCHAIN", 0, "-m state --state ESTABLISHED,RELATED -j ACCEPT"); err != nil {
		log.Println(err)
	}

	if err := fw.DirectAddRulePermanent("ipv4", "filter", "MYCHAIN", 0, "-p udp --dport 53 -j ACCEPT"); err != nil {
		log.Println(err)
	}
	
	if err := fw.DirectAddRulePermanent("ipv4", "filter", "MYCHAIN", 0, "-j REJECT"); err != nil {
		log.Println(err)
	}

	// Reload for changes to take effect immediately
	if err := fw.Reload(); err != nil {
		log.Println(err)
	}
}

Releases

No releases published

Packages

No packages published

Languages