I have a .NET 6 Web API application and I want to edit my iptables rule in hosted system. (the system that Web API run on it)
I have rule like below
-A INPUT -m tcp --protocol tcp --source 2.2.2.2 --destination 1.1.1.1 --source-port 111 --destination-port 222 --jump DROP
I try this rule in iptables command in bash and work correctly, but when I try to create rule for this like below
IpTablesRule rule = IpTablesRule.Parse($"-A INPUT -m tcp--protocol tcp --source 2.2.2.2 --destination 1.1.1.1 --source-port 111 --destination-port 222 --jump DROP", null, chains);
and then try to add to system like below
ipTablesSystem = new IpTablesSystem(system: new LocalFactory(), tableAdapter: new IPTablesBinaryAdapter());
inputChain = ipTablesSystem.GetChain(table: Table.FILTER, chain: Chain.INPUT, ipVersion: (int)IpVersion.V4);
inputChain.AddRule(rule);
No any error rise on system or something like that, but after I try to see system rules with bash (cli) with iptables -L I do not see my rules
Why my rule does not exist in system? and how to resolve this problem?
c#-iptables. This only creates noiseinputChain.AddRuleadds an object to a collection, it doesn't executeiptablesat all. TheIPTablesLibAdapterClient.AddRuledoes. Don't rush to use it though without understanding what's going on because you could end up causing serious problems. Let the deployment script take care of network setup.inputChain.AddRuledoesn't execute anything. API doesn't mean "Web" or "Remote". Yes, there are a lot of libraries but they only work if the executing account has permission to make modifications. And web apps should never, ever have such permissions