The filtering problem is among the fundamental issues in control and signal processing. Several approaches such as H2 optimal filtering and H∞ optimal filtering have been developed to address this issue. While the optimal H2 filtering problem has been extensively studied in the past for linear systems, to the best of our knowledge, it has not been studied for bilinear systems. This is indeed surprising, since bilinear systems are important class of nonlinear systems with well-established theories and applications in various fields. The problem of H2 optimal filtering for both discrete-time and continuous bilinear systems is addressed in this paper. The filter design problem is formulated in the optimization framework. The problem for the discrete-time case is expressed in terms of linear matrix inequalities which can be efficiently solved. The results are used for the optimal filtering of a bilinear model of an electro-hydraulic drive.