Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I should how to insert rules with go-iptables #85

Open
cylonchau opened this issue Apr 12, 2021 · 1 comment
Open

I should how to insert rules with go-iptables #85

cylonchau opened this issue Apr 12, 2021 · 1 comment

Comments

@cylonchau
Copy link

hi ,
I tried insert rule,but I do not what format should be inserted?
go-iptables only get but not insert rules?

version

system version:centos7
golang version:1.15.3

code

func main() {
	ips, err := iptables.New()
	if err != nil {
		panic(err)
	}

	stas, err := ips.StructuredStats("filter", "IN_public_allow")
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n\n	", stas)

	stasstr, err := ips.Stats("filter", "IN_public_allow")

	for _, v := range stasstr {
		if err := ips.Append("filter", "INPUT", v...); err != nil {
			panic(err)
		}
	}

	stasstr, err = ips.Stats("filter", "IN_public_allow")
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n\n	", stasstr)
}

phenomenon

I I tried insert rule,but I do not what format should be inserted?but I tried used Results obtained by go-iptables,but or not insert.

[root@node01 ~]# ./iptables-api 
[]iptables.Stat{iptables.Stat{Packets:0x2, Bytes:0xa8, Target:"ACCEPT", Protocol:"tcp", Opt:"--", Input:"*", Output:"*", Source:(*net.IPNet)(0xc000058870), Destination:(*net.IPNet)(0xc0000588a0), Options:"tcp dpt:22 ctstate NEW,UNTRACKED"}, iptables.Stat{Packets:0x0, Bytes:0x0, Target:"ACCEPT", Protocol:"tcp", Opt:"--", Input:"*", Output:"*", Source:(*net.IPNet)(0xc0000588d0), Destination:(*net.IPNet)(0xc000058900), Options:"tcp dpt:1088 ctstate NEW,UNTRACKED"}}

	panic: running [/usr/sbin/iptables -t filter -A INPUT 2 168 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW,UNTRACKED --wait]: exit status 2: Bad argument `2'
Try `iptables -h' or 'iptables --help' for more information.


goroutine 1 [running]:
main.main()
	/mnt/d/go_work/src/netlink/main.go:58 +0x488

go-iptables generated format cannot be inserted , it's not iptables cli format? I should how to insert rules with go-iptables?

@JerryZhou343
Copy link

use root user to run your process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants