Q: Is it halachically permissible to take advantage of tax shelters and tax loopholes (“tax avoidance”)?
A: The classic case of dina d’malchusa in the Gemara (B.K. 113a) is that of taxes. The king or government, whether Jewish or non-Jewish, is entitled to impose and collect taxes and customs tariffs, provided that the tax is collected in a standard manner, even if some groups pay more than others. A tax collector who acts according to the law acts also with halachic authority (C.M. 369:6).
Nonetheless, it is permissible to take advantage of tax shelters and tax loopholes. For example, if local people are not subject to custom tariffs, Rivash (#2) allows granting merchandise as a gift to a local person when passing customs to avoid the tariff. This is considered “avoidance of taxes” and not “tax evasion,” and is in consonance with dina d’malchusa (Pischei Choshen, Geneivah 1:).
One should consult a professional tax expert in this regard, as the details vary from place to place.